realliyifei Posted January 3, 2022 Share Posted January 3, 2022 (edited) I’m creating a workflow of the same function w.r.t. different browsers depending on which browser is being used, so I set the same hotkey for the links between browser apps and their corresponding AppleScripts. It can work though the workflow highlights the hotkey is overlapped, so I’m wondering is there any better solution? Note that we cannot link one hotkey to two AppleScripts here otherwise it will work on two browser apps simultaneously, which is unnecessary. Edited January 3, 2022 by realliyifei Link to comment
deanishe Posted January 3, 2022 Share Posted January 3, 2022 (edited) 13 minutes ago, realliyifei said: so I’m wondering is there any better solution? No, this is how you're supposed to do it. Alfred's warnings about duplicate hotkeys aren't particularly smart and don't consider when or if they're active. Just because it's orange doesn't mean there's an actual problem. You have to check manually, I'm afraid. 13 minutes ago, realliyifei said: Note that we cannot link one hotkey to two AppleScripts here otherwise it will work on two browser apps simultaneously Not so. Alfred can set an environment variable to the bundle ID of the active application. You can use the variable in your script to run different code for different applications. Also, don't use Run NSAppleScript. Use Run Script with Language = "/usr/bin/osascript (AppleScript)" instead. Run NSAppleScript behaves weirdly, and nobody really knows why. It's best to avoid it if possible. Edited January 3, 2022 by deanishe Link to comment
realliyifei Posted January 3, 2022 Author Share Posted January 3, 2022 (edited) Thanks! I switch to Run Script now. But I fail to figure out how to set the app env var in the Alfred for conditional action? Here’s my workflow demo: with the apple script -- Safari tell application "Safari" set tab_idx to index of current tab of front window close (every tab of front window whose index is not equal to tab_idx) end tell -- Chrome try tell window 1 of application "Google Chrome" to ¬ close (tabs 1 thru (active tab index - 1)) tell window 1 of application "Google Chrome" to ¬ close (tabs -1 thru (active tab index + 1)) end try ``` Edited January 3, 2022 by realliyifei Link to comment
deanishe Posted January 4, 2022 Share Posted January 4, 2022 4 hours ago, realliyifei said: But I fail to figure out how to set the app env var in the Alfred for conditional action? You enter the variable name in the box, not the value. The default is "focusedapp" You can get the variable in AppleScript with set _appname to (system attribute "focusedapp") realliyifei 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now