Skip to content

Instantly share code, notes, and snippets.

@shuxiao9058
Created June 14, 2019 08:58
Show Gist options
  • Save shuxiao9058/1dc0cd670b4766145c13890025f24478 to your computer and use it in GitHub Desktop.
Save shuxiao9058/1dc0cd670b4766145c13890025f24478 to your computer and use it in GitHub Desktop.
Mac Automation Scripts
-- ==================================================================
-- PROGRESS
-- ==================================================================
set progress description to "Daily Sync"
set progress total steps to 2
property progressSteps : 0
on updateProgress(description)
delay 1
set progress additional description to description
set progressSteps to progressSteps + 1
set progress completed steps to progressSteps
end updateProgress
-- ==================================================================
-- START
-- ==================================================================
updateProgress("Starting apps and processes")
on getTodayApps(core, other, work, background)
set today to weekday of (current date)
if (today = Sunday) then
return core & background
else if (today = Saturday) then
return core & other & background
else
return core & other & work & background
end if
end getTodayApps
-- Open native apps
set core to {"Todoist", "Calendar", "Messages", "Mail"}
set other to {"Photos", "Anki", "Spotify", "Slack"}
set work to {}
set background to {"Google Drive", "Google Photos Backup", "Flux", "Slate", "Seil", "Karabiner"}
set nativeApps to getTodayApps(core, other, work, background)
repeat with nativeApp in nativeApps
run application nativeApp
end repeat
-- Open web apps
set core to {"http://www.apple.com/ios/health", "https://myfitnesspal.com"}
set other to {"https://www.rescuetime.com/dashboard", "https://wakatime.com/dashboard", "https://www.mint.com", "https://www.egghead.io", "https://www.codewars.com", "https://buffer.com", "https://www.youtube.com/feed/subscriptions", "https://facebook.com", "https://twitter.com"}
set work to {"https://domo.domo.com/inbox", "https://domo.demo.com/inbox", "https://domo.okta.com/home/jira_onprem/0oa1moe1d0joaWP4P0x7/3549", "https://git.empdev.domo.com/pulls?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr+label%3A%22mobile-web%22", "https://app.getsentry.com/domo-mobile-web/mobileweb"}
set background to {}
set webApps to getTodayApps(core, other, work, background)
repeat with webApp in webApps
do shell script "open " & webApp
end repeat
-- ==================================================================
-- CONFIGURE
-- ==================================================================
updateProgress("Configuring settings")
-- Turn off WiFi
do shell script "networksetup -setairportpower en0 off"
-- Run window manager
delay 1
tell application "System Events"
key code 18 using {command down, option down, control down}
end tell
-- ==================================================================
-- PROGRESS
-- ==================================================================
set progress description to "Domo"
set progress total steps to 2
property progressSteps : 0
on updateProgress(description)
delay 1
set progress additional description to description
set progressSteps to progressSteps + 1
set progress completed steps to progressSteps
end updateProgress
-- ==================================================================
-- START
-- ==================================================================
updateProgress("Starting apps and processes")
-- Open native apps
set nativeApps to {"Todoist", "iTerm", "Google Chrome", "Calendar", "Spotify", "Messages", "Mail", "Dash"}
repeat with nativeApp in nativeApps
run application nativeApp
end repeat
-- Open web apps
set webApps to {"https://domo.domo.com", "https://domo.demo.com", "https://domo.okta.com/home/jira_onprem/0oa1moe1d0joaWP4P0x7/3549", "http://localhost:3000"}
repeat with webApp in webApps
do shell script "open " & webApp
end repeat
-- ==================================================================
-- CONFIGURE
-- ==================================================================
updateProgress("Configuring settings")
-- Open terminal/editor window arrangment
delay 1
tell application "iTerm"
activate
tell application "System Events"
keystroke "r" using {command down, shift down}
end tell
end tell
-- Run window manager
delay 1
tell application "System Events"
key code 18 using {command down, option down, control down}
end tell
-- Fullscreen terminal/editor
delay 1
tell application "iTerm" to activate
tell application "System Events"
key code 36 using {command down}
end tell
-- Open Dev Tools
delay 1
tell application "Google Chrome" to activate
tell application "Google Chrome" to set active tab index of first window to 4
tell application "System Events"
keystroke "i" using {command down, option down}
end tell
-- ==================================================================
-- PROGRESS
-- ==================================================================
set progress description to "Quit All"
set progress total steps to 3
property progressSteps : 0
on updateProgress(description)
delay 1
set progress additional description to description
set progressSteps to progressSteps + 1
set progress completed steps to progressSteps
end updateProgress
-- ==================================================================
-- QUIT
-- ==================================================================
updateProgress("Quitting apps and processes")
-- Close running applications
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder", "quit-all-script"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
display dialog ("Error: An app couldn't be closed!") buttons {"Ok"} with icon caution
end try
-- Kill running processes
set processes to {"node", "phantomjs"}
repeat with process in processes
do shell script "killall " & process & " || true"
end repeat
-- ==================================================================
-- EJECT
-- ==================================================================
updateProgress("Ejecting devices")
-- Eject plugged-in devices
try
tell application "Finder"
eject the disks
end tell
on error
display dialog ("Error: A device couldn't be ejected!") buttons {"Ok"} with icon caution
end try
-- ==================================================================
-- CLEAN
-- ==================================================================
updateProgress("Cleaning directories")
-- Empty trash
tell application "Finder"
empty the trash
end tell
-- Delete contents of Downloads folder
do shell script "rm -rf ~/Downloads/*"
-- Delete all extra node_modules folders
do shell script "find ~/'Google Drive' -name 'node_modules' -type d -exec rm -r '{}' ';' || true"
-- ==================================================================
-- PROGRESS
-- ==================================================================
set progress description to "Screencast End"
set progress total steps to 3
property progressSteps : 0
on updateProgress(description)
delay 1
set progress additional description to description
set progressSteps to progressSteps + 1
set progress completed steps to progressSteps
end updateProgress
-- ==================================================================
-- START
-- ==================================================================
updateProgress("Starting apps and processes")
-- Open native apps
set nativeApps to {"Flux"}
repeat with nativeApp in nativeApps
run application nativeApp
end repeat
-- ==================================================================
-- CONFIGURE
-- ==================================================================
updateProgress("Configuring settings")
-- Reset second monitor's screen resolution back to to best for display
delay 1
tell application "SwitchResX Daemon"
set current mode of display 2 to mode 1 of display 2
end tell
-- Turn on notifications
delay 1
tell application "System Events"
tell application process "SystemUIServer"
try
key down option
click menu bar item "Notification Center, Do Not Disturb enabled" of menu bar 2
key up option
on error
key up option
end try
end tell
end tell
-- ==================================================================
-- QUIT
-- ==================================================================
updateProgress("Quitting apps and processes")
-- Quit native apps
set nativeApps to {"Google Chrome", "SwitchResX Daemon", "ScreenFlow", "Todoist", "iTerm"}
repeat with nativeApp in nativeApps
tell application nativeApp to quit
end repeat
-- ==================================================================
-- PROGRESS
-- ==================================================================
set progress description to "Screencast Start"
set progress total steps to 3
property progressSteps : 0
on updateProgress(description)
delay 1
set progress additional description to description
set progressSteps to progressSteps + 1
set progress completed steps to progressSteps
end updateProgress
-- ==================================================================
-- QUIT
-- ==================================================================
updateProgress("Quitting apps and processes")
-- Quit native apps
set nativeApps to {"Flux"}
repeat with nativeApp in nativeApps
tell application nativeApp to quit
end repeat
-- ==================================================================
-- START
-- ==================================================================
updateProgress("Starting apps and processes")
-- Open native apps
set nativeApps to {"Google Chrome", "SwitchResX Daemon", "ScreenFlow", "Todoist", "iTerm"}
repeat with nativeApp in nativeApps
run application nativeApp
end repeat
-- Open web apps
set webApps to {"https://github.com/trevordmiller?tab=repositories"}
repeat with webApp in webApps
do shell script "open " & webApp
end repeat
-- ==================================================================
-- CONFIGURE
-- ==================================================================
updateProgress("Configuring settings")
-- Switch second monitor's screen resolution to 1280x720 HiDPI
delay 1
tell application "SwitchResX Daemon"
set res to modes of display 2 whose (width = 1280 and height = 720 and definition = 2)
set current mode of display 2 to first item of res
end tell
-- Open terminal/editor profile
delay 1
tell application "iTerm"
create window with profile "demo"
end tell
-- Run window manager
delay 1
tell application "System Events"
key code 18 using {command down, option down, control down}
end tell
-- Fullscreen terminal/editor
delay 1
tell application "iTerm" to activate
tell application "System Events"
key code 36 using {command down}
end tell
-- Turn off notifications
delay 1
tell application "System Events"
tell application process "SystemUIServer"
try
key down option
click menu bar item "Notification Center" of menu bar 2
key up option
on error
key up option
end try
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment