Skip to content

Instantly share code, notes, and snippets.

@francisfeng
francisfeng / save-tabs-safari-anybox.applescript
Last active January 17, 2025 12:44
Save all tabs of Safari’s current window to Anybox
tell application "Safari"
repeat with tabItem in tabs of window 1
set link to URL of tabItem
tell application id "cc.anybox.Anybox"
save link
end tell
end repeat
end tell
@francisfeng
francisfeng / command-c.swift
Last active December 5, 2024 02:17
Simulating Command + C (aka Copy command) in macOS
// 0x08 is key code for "c"
guard let keydownEvent = CGEvent(keyboardEventSource: nil, virtualKey: 0x08, keyDown: true) else { return }
guard let keyupEvent = CGEvent(keyboardEventSource: nil, virtualKey: 0x08, keyDown: false) else { return }
keydownEvent.flags = CGEventFlags.maskCommand
keydownEvent.post(tap: CGEventTapLocation.cghidEventTap)
keyupEvent.flags = CGEventFlags.maskCommand;
keyupEvent.post(tap: CGEventTapLocation.cghidEventTap)
// For it to work, Accessibility needs to be enabled in