Created
June 22, 2020 14:02
-
-
Save OKsign/7bd095a24ae82dc3289262c8657e39df to your computer and use it in GitHub Desktop.
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
-- user input | |
set network_name to "iPhone" | |
set apps to {"audacity", "calculator"} | |
-- end of user input | |
-- user options | |
set no_connection_then_quit_apps to "off" -- "on" or "off" | |
-- end of user options | |
if network_name is "" or (count apps) = 0 then | |
display dialog "Edit User Input in Script File." with title "Script 46" | |
return | |
end if | |
tell application "System Events" to tell process "SystemUIServer" | |
set aa to value of attribute "AXDescription" of menu bar items of menu bar 1 | |
end tell | |
set apple_std to text item delimiters | |
set text item delimiters to ", " | |
set out_of_list to aa as text | |
set text item delimiters to apple_std | |
repeat until out_of_list contains network_name | |
tell application "System Events" to tell process "SystemUIServer" | |
set aa to value of attribute "AXDescription" of menu bar items of menu bar 1 | |
end tell | |
set apple_std to text item delimiters | |
set text item delimiters to ", " | |
set out_of_list to aa as text | |
delay 5 | |
end repeat | |
repeat with i in apps | |
if i is not "" then | |
if application i is not running then | |
tell application i | |
launch | |
end tell | |
end if | |
end if | |
end repeat | |
display notification "Done!" with title "Script 46" | |
if no_connection_then_quit_apps is "on" then | |
tell application "System Events" to tell process "SystemUIServer" | |
set aa to value of attribute "AXDescription" of menu bar items of menu bar 1 | |
end tell | |
set apple_std to text item delimiters | |
set text item delimiters to ", " | |
set out_of_list to aa as text | |
set text item delimiters to apple_std | |
repeat until out_of_list does not contain network_name | |
tell application "System Events" to tell process "SystemUIServer" | |
set aa to value of attribute "AXDescription" of menu bar items of menu bar 1 | |
end tell | |
set apple_std to text item delimiters | |
set text item delimiters to ", " | |
set out_of_list to aa as text | |
delay 5 | |
end repeat | |
tell application "System Events" | |
set activeApp to (get name of first process where it is frontmost) | |
end tell | |
set apple_std to text item delimiters | |
set text item delimiters to ", " | |
set out_of_list_apps to apps as text | |
set text item delimiters to apple_std | |
tell application activeApp | |
set quit_or_cancel to (display dialog "Are You Sure You Want to Quit \"" & out_of_list_apps & "\"?" buttons {"Cancel", "Quit"} with title "Script 46") | |
end tell | |
repeat with i in apps | |
if i is not "" then | |
if application i is running then | |
tell application i | |
quit | |
end tell | |
end if | |
end if | |
end repeat | |
display notification "Done!" with title "Script 46" | |
end if | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment