My AppleScripts collection
- write-to-log
- mail-message-count
- ping-and-reconnect
- play-sound
- process-files-with-ffmpeg
- Files and folders
- listing-window-items
- toggle-bluetooth-state
- toggle-airdrop-discoverability
Shared-ish script with logging function to call from other scripts. It logs strings to the specified text file.
The script shows message count for each mailbox in all accounts. The information is displayed in the log. You can get all messages count, or only unread ones, or only flagged ones by re-commenting corresponding lines.
This one pings some website URL to check internet connection, and if ping fails, then script restarts the network interface (turns off and on again). It helps when you are connected via WiFi and suddenly everything loses connection.
Plays a sound file with afplay
. Can be used to play notifications when finishing some task.
Gets a list of files and iterates through them, processing each with FFmpeg. Here's an article about creating a Service based on that.
Given the filename /Users/yourname/temp/log.txt
returns txt
.
Given the filename /Users/yourname/temp/log.txt
returns /Users/yourname/temp/log
.
Given the path /Users/yourname/temp/
returns temp
.
$ sw_vers -productVersion
13.5.2
$ osascript ./list-menu-bar-items.applescript
Available menu bar items
- Clock
- Control Centre
- Wi‑Fi, connected, 3 bars
- Battery
- Bluetooth
- Shortcuts
$ sw_vers -productVersion
13.5.2
$ osascript ./try-to-list-window-items-properties.applescript
toggle button
missing value
class:checkbox, minimum value:missing value, orientation:missing value, position:1386, 46, accessibility description:missing value, role description:toggle button, focused:missing value, title:missing value, size:134, 41, help:missing value, entire contents:, enabled:true, maximum value:missing value, role:AXCheckBox, value:1, subrole:AXToggle, selected:missing value, name:missing value, description:toggle button
item 1 of checkbox 1 of group 1 of window Control Centre of application process ControlCenter
-
toggle button
missing value
class:checkbox, minimum value:missing value, orientation:missing value, position:1530, 40, accessibility description:missing value, role description:toggle button, focused:missing value, title:missing value, size:134, 62, help:missing value, entire contents:, enabled:true, maximum value:missing value, role:AXCheckBox, value:0, subrole:AXToggle, selected:missing value, name:missing value, description:toggle button
item 1 of checkbox 2 of group 1 of window Control Centre of application process ControlCenter
-
...
Might fail in different scenarios because of the wrong index, or inability to get "every item", or else
Toggles Bluetooth state via Menu Bar icon (requires user to add Bluetooth icon on Menu Bar via Control Centre Modules in System Settings):
$ sw_vers -productVersion
13.5.2
$ osascript ./toggle-bluetooth-state-via-menu-bar-icon.applescript 1
Toggles Bluetooth state via Control Centre:
$ sw_vers -productVersion
13.5.2
$ osascript ./toggle-bluetooth-state-via-control-centre.applescript 1
Toggles AirDrop discoverability between No One
(1
), Contacts Only
(2
) and Everyone
(3
). Optionally toggles off Bluetooth too:
$ TOGGLE_OFF_BLUETOOTH=1 osascript ./toggle-airdrop-discoverability.applescript 2