Created
August 29, 2020 09:47
-
-
Save OKsign/eb4910c4bbfec518af4b8c33e941819a 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 options | |
set save_active_document to "off" -- "on" or "off" | |
set save_new_document_do_not_minimize to "off" -- "on" or "off" | |
-- end of user options | |
tell application "System Events" | |
set activeApp to (get name of first process where it is frontmost) | |
end tell | |
tell application "System Events" | |
set all_win_activeapp to name of window of process activeApp | |
end tell | |
tell application "System Events" | |
tell process activeApp | |
if (menu bar item "File" of menu bar 1) exists then | |
tell application "System Events" | |
tell process activeApp | |
set file_menu_list to name of every menu item of menu 1 of menu bar item "File" of menu bar 1 | |
end tell | |
end tell | |
repeat with i from 1 to count file_menu_list | |
if (item i of file_menu_list) starts with "save" then | |
if (item i of file_menu_list) does not contain "playlist" then | |
set doc_app to 1 | |
exit repeat | |
else | |
set doc_app to 0 | |
end if | |
end if | |
end repeat | |
else | |
set doc_app to 0 | |
end if | |
end tell | |
end tell | |
if doc_app is 1 then | |
if save_active_document is "on" then | |
delay 1.5 | |
-- check - active doc exists | |
repeat with i from 1 to count all_win_activeapp | |
if (item i of all_win_activeapp) is not missing value then | |
tell application "System Events" | |
tell process activeApp | |
set myValue to (value of attribute "AXMenuItemMarkChar" of menu item (item i of all_win_activeapp) of menu 1 of menu bar item "Window" of menu bar 1 as string) | |
end tell | |
end tell | |
if myValue is "✓" then | |
set do_save_active_doc to 1 | |
exit repeat | |
else | |
set do_save_active_doc to 0 | |
end if | |
end if | |
end repeat | |
-- end - check - active doc exists | |
if do_save_active_doc is 1 then | |
tell application "System Events" | |
keystroke "s" using command down | |
end tell | |
end if | |
end if | |
repeat with i from 1 to count all_win_activeapp | |
if (item i of all_win_activeapp) is not missing value then | |
tell application "System Events" | |
tell process activeApp | |
set myValue to (value of attribute "AXMenuItemMarkChar" of menu item (item i of all_win_activeapp) of menu 1 of menu bar item "Window" of menu bar 1 as string) | |
end tell | |
end tell | |
if myValue is "◆" then | |
tell application "System Events" | |
tell process activeApp | |
click (menu item (item i of all_win_activeapp) of menu 1 of menu bar item "Window" of menu bar 1) | |
end tell | |
end tell | |
delay 1.2 | |
tell application "System Events" | |
tell process activeApp | |
set docPath1 to value of attribute "AXDocument" of window 1 | |
end tell | |
end tell | |
if docPath1 is not missing value then | |
if docPath1 contains "%20" then | |
set prevTIDs to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to the "%20" | |
set the item_list to every text item of docPath1 | |
set AppleScript's text item delimiters to the " " | |
set docPath1 to the item_list as string | |
set AppleScript's text item delimiters to prevTIDs | |
end if | |
if docPath1 contains "%" then | |
set prevTIDs to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to the "%25" | |
set the item_list to every text item of docPath1 | |
set AppleScript's text item delimiters to the "%" | |
set docPath1 to the item_list as string | |
set AppleScript's text item delimiters to prevTIDs | |
end if | |
if docPath1 contains "localhost" then -- remove characters | |
set docPath2 to ((characters 17 thru -1 of docPath1) as string) | |
else | |
set docPath2 to ((characters 8 thru -1 of docPath1) as string) | |
end if | |
set activeDoc to POSIX file docPath2 | |
set name_file to do shell script "basename " & quoted form of POSIX path of activeDoc | |
-- get folder path | |
set prevTIDs to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to the name_file | |
set the item_list to every text item of docPath2 | |
set AppleScript's text item delimiters to the "" | |
set folder_path to the item_list as string | |
set AppleScript's text item delimiters to prevTIDs | |
set folder_path_posix to POSIX file folder_path | |
tell application "Finder" | |
open folder_path_posix | |
set selection to activeDoc | |
set sel to the selection | |
set m1 to modification date of item 1 of sel | |
end tell | |
tell application "System Events" | |
keystroke "s" using command down | |
end tell | |
tell application "Finder" | |
set selection to activeDoc | |
set sel to the selection | |
set m2 to modification date of item 1 of sel | |
end tell | |
repeat until m1 is not m2 | |
tell application "Finder" | |
set sel to the selection | |
set m2 to modification date of item 1 of sel | |
end tell | |
end repeat | |
tell application "System Events" | |
tell process activeApp | |
click (menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1) | |
end tell | |
end tell | |
tell application "Finder" | |
close window 1 | |
end tell | |
end if | |
if docPath1 is missing value and save_new_document_do_not_minimize is "off" then | |
tell application "System Events" | |
tell process activeApp | |
click (menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1) | |
end tell | |
end tell | |
end if | |
if docPath1 is missing value and save_new_document_do_not_minimize is "on" then | |
tell application "System Events" | |
keystroke "s" using command down | |
end tell | |
end if | |
end if | |
end if | |
end repeat | |
delay 1 | |
display notification "Done!" with title "Script 45.1" | |
end if | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment