- Open Automator
- Click Service if the menu opens, otherwise File -> New -> Quick Action
- Set "Workflow receives" to "no input"
- In the left panel, click utilities -> Run AppleScript -> Copy and Paste one of the applescript from one of the attached files.
- Click File -> Save. Take note of what you saved the service as
- Go to System Preferences -> Keyboard -> Shortcuts -> Services and scroll all the way to the bottom. Your service should be here and you can set the key sequence.
- Open some application and test if the sequence works.
Last active
December 17, 2019 22:42
-
-
Save pryorda/c68b69b95244afc3c5487a047a2efa8a to your computer and use it in GitHub Desktop.
Creating KeyBoard Shortcuts that work on MAC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on getFrontAppPath() | |
set frontAppPath to (path to frontmost application) as text | |
set myPath to (path to me) as text | |
if frontAppPath is myPath then | |
try | |
tell application "Finder" to set bundleID to id of file myPath | |
tell application "System Events" to set visible of (first process whose bundle identifier is bundleID) to false | |
-- we need to delay because it takes time for the process to hide | |
-- I noticed this when running the code as an application from the applescript menu bar item | |
set inTime to current date | |
repeat | |
set frontAppPath to (path to frontmost application) as text | |
if frontAppPath is not myPath then exit repeat | |
if (current date) - inTime is greater than 1 then exit repeat | |
end repeat | |
end try | |
end if | |
return frontAppPath | |
end getFrontAppPath | |
tell application "Terminal" | |
set frontAppPath to my getFrontAppPath() | |
create window "/usr/local/bin/lpass show --sync=now --clip -q --password AD" | |
activate | |
delay 0.2 | |
tell application frontAppPath to activate | |
end tell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set myScript to "/usr/local/bin/lpass show --sync=now --clip -q --password AD; exit" | |
tell application "Terminal" | |
activate | |
do script myScript | |
end tell | |
set isBusy to true | |
repeat until isBusy is false | |
tell application "Terminal" | |
tell window 1 | |
set isBusy to busy as boolean --> Test if busy | |
end tell | |
end tell | |
delay 1 --> Check every second | |
end repeat | |
tell me to activate | |
# display dialog "Terminal is No Longer Busy!" | |
my displayDialog() | |
on displayDialog() | |
display notification "Password Copied" with title "LastPass CLI" sound name "Submarine" | |
end displayDialog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if application "iTerm" is running then | |
tell application "iTerm" | |
create window with default profile | |
activate | |
end tell | |
else | |
tell application "iTerm" | |
activate | |
end tell | |
end if |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if application "Terminal" is running then | |
tell application "Terminal" | |
activate | |
end tell | |
else | |
tell application "Terminal" | |
do script "" | |
activate | |
end tell | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment