├── README.md └── scripts ├── app ├── activate.applescript ├── get-bounds.applescript ├── hide.applescript ├── is-hidden.applescript ├── is-mini.applescript └── is-running.applescript ├── chrome └── open-url.applescript ├── macos ├── add-to-login-items.applescript ├── list-login-items.applescript └── remove-from-login-items.applescript └── reminders ├── count-list.applescript ├── get-lists.applescript ├── get-reminders-in-list.applescript ├── hide-sidebar.applescript └── switch-list.applescript /README.md: -------------------------------------------------------------------------------- 1 |

2 | sparkles 3 |

4 |

awesome-applescripts

5 |
6 | A collection of awesome, useful, not-so-obvious applescripts. 7 |
8 | 9 | ### Table of Contents 10 | 11 | - [Scripting Applications](#-scripting-applications) 12 | - [Scripting macOS](#-scripting-macos) 13 | - [Scripting Chrome](#-scripting-chrome) 14 | - [Scripting Reminders](#-scripting-reminders) 15 | 16 | ### → Scripting Applications 17 | 18 | **Get bounds of application window** 19 | 20 | ```sh 21 | $ osascript scripts/app/get-bounds.applescript Safari 22 | ``` 23 | 24 | **Hide application** 25 | 26 | ```sh 27 | $ osascript scripts/app/hide.applescript Safari 28 | ``` 29 | 30 | **Check if application is hidden** 31 | 32 | ```sh 33 | $ osascript scripts/app/is-hidden.applescript Safari 34 | ``` 35 | 36 | 37 | **Check if application is miniaturized (minimized)** 38 | 39 | ```sh 40 | $ osascript scripts/app/is-mini.applescript Safari 41 | ``` 42 | 43 | 44 | **Check if application is running** 45 | 46 | ```sh 47 | $ osascript scripts/app/is-running.applescript Safari 48 | ``` 49 | 50 | ### → Scripting MacOS 51 | 52 | _Help wanted._ 53 | 54 | 55 | ### → Scripting Chrome 56 | 57 | **Open (or highlight tab if already open) a URL** 58 | 59 | ```sh 60 | $ osascript scripts/chrome/open-url.applescript https://news.ycombinator.com/ 61 | ``` 62 | 63 | 64 | ### → Scripting Reminders 65 | 66 | **Get reminders in list** 67 | 68 | ```sh 69 | $ osascript scripts/reminders/get-reminders-in-list.applescript "Today" 70 | ``` 71 | 72 | **Get all lists** 73 | 74 | ```sh 75 | $ osascript scripts/reminders/get-lists.applescript 76 | ``` 77 | 78 | **Hide the sidebar** 79 | 80 | ```sh 81 | $ osascript scripts/reminders/hide-sidebar.applescript Safari 82 | ``` 83 | 84 | **Switch to a different list** 85 | 86 | ```sh 87 | $ osascript scripts/reminders/switch-list.applescript "Grocery List" 88 | ``` 89 | 90 | **Count a list** 91 | 92 | ```sh 93 | $ osascript scripts/reminders/count-list.applescript "Grocery List" 94 | ``` 95 | 96 | 97 | ### License 98 | 99 | MIT 100 | -------------------------------------------------------------------------------- /scripts/app/activate.applescript: -------------------------------------------------------------------------------- 1 | on run argv 2 | if (count of argv) > 0 then 3 | set app_name to item 1 of argv 4 | end if 5 | 6 | tell application app_name 7 | reopen 8 | activate 9 | end tell 10 | end run 11 | -------------------------------------------------------------------------------- /scripts/app/get-bounds.applescript: -------------------------------------------------------------------------------- 1 | on run argv 2 | if (count of argv) > 0 then 3 | set app_name to item 1 of argv 4 | end if 5 | 6 | tell application app_name 7 | get bounds of front window 8 | end tell 9 | end run 10 | -------------------------------------------------------------------------------- /scripts/app/hide.applescript: -------------------------------------------------------------------------------- 1 | on run argv 2 | if (count of argv) > 0 then 3 | set app_name to item 1 of argv 4 | end if 5 | 6 | tell application "System Events" 7 | if visible of process app_name is true then 8 | set visible of application process app_name to false 9 | end if 10 | end tell 11 | end run 12 | -------------------------------------------------------------------------------- /scripts/app/is-hidden.applescript: -------------------------------------------------------------------------------- 1 | on run argv 2 | if (count of argv) > 0 then 3 | set app_name to item 1 of argv 4 | end if 5 | 6 | set is_visible to visible of window 1 of application app_name 7 | return not is_visible 8 | end run 9 | -------------------------------------------------------------------------------- /scripts/app/is-mini.applescript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/osascript 2 | 3 | on run argv 4 | if (count of argv) > 0 then 5 | set app_name to item 1 of argv as text 6 | end if 7 | 8 | tell application app_name 9 | repeat with rem_window in every window 10 | try 11 | set is_mini to (get miniaturized of rem_window) 12 | on error msg number -1700 13 | log msg 14 | end try 15 | end repeat 16 | end tell 17 | 18 | return is_mini 19 | end run 20 | -------------------------------------------------------------------------------- /scripts/app/is-running.applescript: -------------------------------------------------------------------------------- 1 | on is_running(app_name) 2 | tell application "System Events" to (name of processes) contains app_name 3 | end is_running 4 | 5 | on run argv 6 | if (count of argv) > 0 then 7 | set app_name to item 1 of argv 8 | end if 9 | 10 | return is_running(app_name) 11 | end run 12 | -------------------------------------------------------------------------------- /scripts/chrome/open-url.applescript: -------------------------------------------------------------------------------- 1 | (* 2 | Copyright (c) 2015-present, Facebook, Inc. 3 | 4 | This source code is licensed under the MIT license found in the 5 | LICENSE file in the root directory of this source tree. 6 | *) 7 | 8 | property targetTab: null 9 | property targetTabIndex: -1 10 | property targetWindow: null 11 | 12 | on run argv 13 | set theURL to item 1 of argv 14 | 15 | tell application "Chrome" 16 | 17 | if (count every window) = 0 then 18 | make new window 19 | end if 20 | 21 | -- 1: Looking for tab running debugger 22 | -- then, Reload debugging tab if found 23 | -- then return 24 | set found to my lookupTabWithUrl(theURL) 25 | if found then 26 | set targetWindow's active tab index to targetTabIndex 27 | tell targetTab to reload 28 | tell targetWindow to activate 29 | set index of targetWindow to 1 30 | return 31 | end if 32 | 33 | -- 2: Looking for Empty tab 34 | -- In case debugging tab was not found 35 | -- We try to find an empty tab instead 36 | set found to my lookupTabWithUrl("chrome://newtab/") 37 | if found then 38 | set targetWindow's active tab index to targetTabIndex 39 | set URL of targetTab to theURL 40 | tell targetWindow to activate 41 | return 42 | end if 43 | 44 | -- 3: Create new tab 45 | -- both debugging and empty tab were not found 46 | -- make a new tab with url 47 | tell window 1 48 | activate 49 | make new tab with properties {URL:theURL} 50 | end tell 51 | end tell 52 | end run 53 | 54 | -- Function: 55 | -- Lookup tab with given url 56 | -- if found, store tab, index, and window in properties 57 | -- (properties were declared on top of file) 58 | on lookupTabWithUrl(lookupUrl) 59 | tell application "Chrome" 60 | -- Find a tab with the given url 61 | set found to false 62 | set theTabIndex to -1 63 | repeat with theWindow in every window 64 | set theTabIndex to 0 65 | repeat with theTab in every tab of theWindow 66 | set theTabIndex to theTabIndex + 1 67 | if (theTab's URL as string) contains lookupUrl then 68 | -- assign tab, tab index, and window to properties 69 | set targetTab to theTab 70 | set targetTabIndex to theTabIndex 71 | set targetWindow to theWindow 72 | set found to true 73 | exit repeat 74 | end if 75 | end repeat 76 | 77 | if found then 78 | exit repeat 79 | end if 80 | end repeat 81 | end tell 82 | return found 83 | end lookupTabWithUrl 84 | -------------------------------------------------------------------------------- /scripts/macos/add-to-login-items.applescript: -------------------------------------------------------------------------------- 1 | 2 | set app_name to "[ UNIQUE ID TO REGISTER LOGIN ITEM ]" 3 | set app_path to "[ path/to/your.app ]" 4 | set is_hidden to false 5 | 6 | set posix_app_path to (POSIX path of app_path) 7 | set app_file to (POSIX file posix_app_path) 8 | set login_item_path to POSIX path of alias app_file 9 | 10 | tell application "System Events" 11 | make login item at end with properties { name: app_name, path: login_item_path, hidden: is_hidden } 12 | end tell 13 | 14 | log "Added" & app_name & "to login items." 15 | -------------------------------------------------------------------------------- /scripts/macos/list-login-items.applescript: -------------------------------------------------------------------------------- 1 | tell application "System Events" to get the name of every login item 2 | -------------------------------------------------------------------------------- /scripts/macos/remove-from-login-items.applescript: -------------------------------------------------------------------------------- 1 | set item_name to "[ NAME OF LOGIN ITEM ]" 2 | tell application "System Events" to delete login item item_name 3 | -------------------------------------------------------------------------------- /scripts/reminders/count-list.applescript: -------------------------------------------------------------------------------- 1 | on run argv 2 | if (count of argv) > 0 then 3 | set reminder_list to item 1 of argv 4 | else 5 | error "Please provide a list name as the first argument to this script" 6 | end if 7 | 8 | tell application "Reminders" 9 | set the_list to list reminder_list 10 | set the_reminders to (reminders in the_list whose completed is false) 11 | set list_size to count of the_reminders 12 | return list_size 13 | end tell 14 | end run 15 | -------------------------------------------------------------------------------- /scripts/reminders/get-lists.applescript: -------------------------------------------------------------------------------- 1 | tell application "Reminders" to set todo_lists to (get name of every list) 2 | return todo_lists 3 | -------------------------------------------------------------------------------- /scripts/reminders/get-reminders-in-list.applescript: -------------------------------------------------------------------------------- 1 | on run argv 2 | if (count of argv) > 0 then 3 | set reminder_list to item 1 of argv 4 | else 5 | error "Please provide a list name as the first argument to this script" 6 | end if 7 | 8 | tell application "Reminders" 9 | set the_list to list reminder_list 10 | set the_reminders to (reminders in the_list whose completed is false) 11 | 12 | set human_readable_reminders to { } 13 | repeat with the_reminder in the_reminders 14 | set end of human_readable_reminders to name of the_reminder 15 | end repeat 16 | 17 | return human_readable_reminders 18 | end tell 19 | end run 20 | -------------------------------------------------------------------------------- /scripts/reminders/hide-sidebar.applescript: -------------------------------------------------------------------------------- 1 | #!/usr/bin/osascript 2 | 3 | tell application "System Events" 4 | 5 | try 6 | -- Attempt to show the sidebar. If it throws 7 | -- an error, we know the sidebar is already 8 | -- open, so we close it. 9 | -- If it works, we immediately close it. 10 | tell process "Reminders" 11 | click menu item "Show Sidebar" of menu "View" of menu bar 1 12 | end tell 13 | 14 | keystroke "s" using {option down, command down} 15 | on error errMsg 16 | -- Close the sidebar because it's open. 17 | log "Sidebar was open...closing." 18 | keystroke "s" using {option down, command down} 19 | end try 20 | 21 | end tell 22 | -------------------------------------------------------------------------------- /scripts/reminders/switch-list.applescript: -------------------------------------------------------------------------------- 1 | 2 | on run argv 3 | if (count of argv) > 0 then 4 | set rem_list to item 1 of argv 5 | end if 6 | 7 | tell application "Reminders" to show list rem_list 8 | end run 9 | --------------------------------------------------------------------------------