Would that approach hold true for Firefox too? If so that would cover the three main (Mac) web browsers.
Out of reach, alas. Firefox doesn’t provide an osascript interface.
(THO ⌘L ⌘C can be emulated with the System Events (keystroke … using command down) technique – macos - MacOSX or AppleScript: get current URL from Firefox - Stack Overflow )
And I notice that Hook.app are using a more elaborate version of a gui-scripting ⌘L, Edit > Copy approach, which suggests that they may have found intermittent misses with the simple System Events key down events in FireFox:
--(c) CogSci (Hook.app)
use framework "AppKit"
-- classes, constants, and enums used
property NSShiftKeyMask : a reference to 131072
property NSAlternateKeyMask : a reference to 524288
property NSControlKeyMask : a reference to 262144
property NSEvent : a reference to current application's NSEvent
set modifier_down to true
repeat while modifier_down
set modifier_flags to NSEvent's modifierFlags()
set option_down to ((modifier_flags div (get NSAlternateKeyMask)) mod 2) = 1
set shift_down to ((modifier_flags div (get NSShiftKeyMask)) mod 2) = 1
set control_down to ((modifier_flags div (get NSControlKeyMask)) mod 2) = 1
set modifier_down to option_down or shift_down or control_down
end repeat
tell application "Firefox"
activate
delay 0.05
end tell
tell application "System Events"
keystroke "l" using {command down}
keystroke (key code 53)
keystroke (key code 53)
--keystroke "c" using {command down}
tell process "Firefox"
click menu item "Copy" of menu "Edit" of menu bar 1
end tell
delay 0.05
set theClipboard to current application's NSPasteboard's generalPasteboard's stringForType:(current application's NSPasteboardTypeString)
return the theClipboard as string
end tell
2 Likes