Skip to content

Instantly share code, notes, and snippets.

@khurshid-alam
Created June 16, 2024 16:27
Show Gist options
  • Save khurshid-alam/35dca4414a3124515bb0647959c173a1 to your computer and use it in GitHub Desktop.
Save khurshid-alam/35dca4414a3124515bb0647959c173a1 to your computer and use it in GitHub Desktop.
(async()=>{
AS=s=>(runAppleScript(s))
PA=n=>{trigger_action({json:JSON.stringify({BTTPredefinedActionType:n})})}
a=await get_string_variable("hovered_element_details")
v=i=>(a.split('AX'+i+': "')[1].split('"')[0])
F=v('Subrole').slice(2,4)˛
console.log("Hello world!")
// Extract the application name from the URL
let appName = decodeURIComponent(v('URL')).slice(7,-1).split('/').pop().split('.')[0]
if(F=="Ap" && (v('IsApplicationRunning')*1)){
// Use AppleScript to handle the logic for minimizing/unminimizing
await AS(`
tell application "System Events" to tell process "${appName}"
set windowCount to count of windows
if windowCount is 1 then
set theWindow to first window
set isMinimized to value of attribute "AXMinimized" of theWindow
if isMinimized then
-- Unminimize the window
set value of attribute "AXMinimized" of theWindow to false
else
-- Minimize the window
set value of attribute "AXMinimized" of theWindow to true
end if
end if
end tell
`);
} else if(F=="Sp"||F=="Tr"||F=="Se"||F==""){
AS(`beep`)
}
returnToBTT(f);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment