Skip to content

Instantly share code, notes, and snippets.

@Blendertom
Created November 22, 2024 08:49
Show Gist options
  • Save Blendertom/e700e2b6544c053d8a45569e5e77c8dc to your computer and use it in GitHub Desktop.
Save Blendertom/e700e2b6544c053d8a45569e5e77c8dc to your computer and use it in GitHub Desktop.
Get Address script to get Zen Browser working with Hookmark.
-- To make it work, add Zen Browser as an app in from the Scripts tab in Hookmark, and then past this script in the Get Address tab
use scripting additions
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 "Zen Browser"
activate
delay 0.05
set myName to get name of front window
set firefoxVer to version
considering numeric strings
set is87 to firefoxVer ≥ "87"
set is72 to firefoxVer ≥ "72"
end considering
if is72 and myName ends with " - Zen Browser" then
if length of myName > 18 then
set myName to text 1 through -19 of myName
else
set myName to ""
end if
end if
end tell
if is87 then
try
set theUrl to ""
tell application "Zen Browser"
tell application "System Events"
if toolbar "Navigation" of first group of front window of application process "Zen Browser" exists then
set theUrl to get value of UI element 1 of combo box 1 of toolbar "Navigation" of first group of front window of application process "Zen Browser"
else if toolbar "导航" of first group of front window of application process "Zen Browser" exists then
set theUrl to get value of UI element 1 of combo box 1 of toolbar "导航" of first group of front window of application process "Zen Browser"
else if toolbar "Área de navegación" of first group of front window of application process "Zen Browser" exists then
set theUrl to get value of UI element 1 of combo box 1 of toolbar "Área de navegación" of first group of front window of application process "Zen Browser"
else if toolbar "Navigazione" of first group of front window of application process "Zen Browser" exists then
set theUrl to get value of UI element 1 of combo box 1 of toolbar "Navigazione" of first group of front window of application process "Zen Browser"
else if toolbar "ナビゲーション" of first group of front window of application process "Zen Browser" exists then
set theUrl to get value of UI element 1 of combo box 1 of toolbar "ナビゲーション" of first group of front window of application process "Zen Browser"
else if toolbar "導覽" of first group of front window of application process "Zen Browser" exists then
set theUrl to get value of UI element 1 of combo box 1 of toolbar "導覽" of first group of front window of application process "Zen Browser"
else if toolbar "Navegação" of first group of front window of application process "Zen Browser" exists then
set theUrl to get value of UI element 1 of combo box 1 of toolbar "Navegação" of first group of front window of application process "Zen Browser"
end if
if theUrl is not "" then
return ("[" & myName & "](" & theUrl) & ")"
end if
end tell
end tell
end try
end if
tell application "System Events"
keystroke "l" using {command down}
keystroke (key code 53)
keystroke (key code 53)
--keystroke "c" using {command down}
delay 0.2
tell process "Zen Browser"
keystroke "c" using {command down}
delay 0.3
repeat 50 times -- poll clipboard for 5 seconds
try
set myText to (the clipboard)
if myText is not equal to "" then
exit repeat
end if
end try
delay 0.1
end repeat
end tell
set theClipboard to current application's NSPasteboard's generalPasteboard's stringForType:(current application's NSPasteboardTypeString)
return ("[" & myName & "](" & the theClipboard as string) & ")"
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment