Created
January 20, 2022 11:39
-
-
Save OKsign/294c0e66f3b256bfdbc5271ef5111774 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
set list_total_condition to {} | |
---------------------------------------------------------------------- | |
-- user input - add apps/files | |
set F1_1 to "" | |
set F1_2 to "" | |
set F1_3 to "" | |
set F1_4 to "" | |
set F1_5 to "" | |
set F1_6 to "" | |
set F1_7 to "" | |
set F1_8 to "" | |
set F1_9 to "" | |
set F1_10 to "" | |
set F1_11 to "" | |
set F1_12 to "" | |
set F1_13 to "" | |
set F1_14 to "" | |
set F1_15 to "" | |
set F1_16 to "" | |
set F1_17 to "" | |
set F1_18 to "" | |
set F1_19 to "" | |
set F1_20 to "" | |
-- end of user input - add apps/files | |
-- user input - code | |
-- PASTE BELOW. -------------------------------------------------- | |
-- END - PASTE BELOW | |
---------------------------------------------------------------------- | |
-- end of user input - code | |
-- user options | |
set wait_for_windows_in_secs to 60 | |
set check_windows_every_in_secs to 1 | |
-- end of user options ---------------------------------------------- | |
set F1 to {F1_1, F1_2, F1_3, F1_4, F1_5, F1_6, F1_7, F1_8, F1_9, F1_10, F1_11, F1_12, F1_13, F1_14, F1_15, F1_16, F1_17, F1_18, F1_19, F1_20} | |
set list_posix to {} | |
repeat with i from 1 to 20 | |
if (item i of F1) is not "" then | |
set posix_file to POSIX file (item i of F1) | |
copy posix_file to the end of list_posix | |
end if | |
end repeat | |
repeat with i from 1 to count list_posix | |
tell application "Finder" | |
delay 0.02 | |
open (item i of list_posix) | |
end tell | |
end repeat | |
if check_windows_every_in_secs > wait_for_windows_in_secs then | |
display dialog "check_windows_every_in_secs must be less than wait_for_windows_in_secs." with title "Edit Script 37.1 --> User Options" | |
return | |
end if | |
set user_repeat to wait_for_windows_in_secs / check_windows_every_in_secs | |
set user_delay to check_windows_every_in_secs | |
if (count list_total_condition) is not 0 then | |
set list_condition_not_met to {} | |
repeat user_repeat times | |
set list_all_windows to {} | |
tell application "System Events" | |
delay user_delay | |
set allWindows to name of window of processes whose visible is true | |
end tell | |
repeat with i in allWindows | |
repeat with j in i | |
if contents of j is not missing value then set end of list_all_windows to contents of j | |
end repeat | |
end repeat | |
tell application "System Events" | |
set open_apps_with_window to get the name of every process whose background only is false | |
delay 0.03 | |
end tell | |
set list_done to {} | |
set total_item_sub_list to 6 | |
set list_target_windows to {} | |
set list_target_windows_no_dup to {} | |
set list_target_apps to {} | |
set list_target_apps_no_dup to {} | |
set pos_first_target_win to 5 | |
set pos_first_target_app to 6 | |
set num to last item of prop_window | |
repeat with i from 0 to (num - 1) | |
set pos_target_app to pos_first_target_app + (total_item_sub_list * i) | |
set pos_target_window to pos_first_target_win + (total_item_sub_list * i) | |
copy item (pos_target_window) of prop_window to the end of list_target_windows | |
copy item (pos_target_app) of prop_window to the end of list_target_apps | |
end repeat | |
repeat with i from 1 to count list_target_windows | |
if item i of list_target_windows is not in list_target_windows_no_dup then | |
copy item i of list_target_windows to the end of list_target_windows_no_dup | |
end if | |
end repeat | |
repeat with i from 1 to count list_target_apps | |
if item i of list_target_apps is not in list_target_apps_no_dup then | |
copy item i of list_target_apps to the end of list_target_apps_no_dup | |
end if | |
end repeat | |
repeat with i from 1 to count list_target_apps_no_dup | |
if item i of list_target_apps_no_dup is not in open_apps_with_window then | |
set condition_met_apps to 0 | |
set condition_met to 0 | |
exit repeat | |
else | |
set condition_met_apps to 1 | |
end if | |
end repeat | |
if condition_met_apps is 1 then | |
repeat with i from 1 to count list_target_windows_no_dup | |
if item i of list_target_windows_no_dup is not in list_all_windows then | |
set condition_met to 0 | |
exit repeat | |
else | |
set condition_met to 1 | |
end if | |
end repeat | |
else | |
set condition_met to 0 | |
end if | |
if condition_met is 1 then | |
copy "1" to the end of list_done | |
repeat with i from 1 to num | |
set pos_app_to_activate to 6 * i | |
set pos_window_to_activate to pos_app_to_activate - 1 | |
set pos_siz2 to pos_window_to_activate - 1 | |
set pos_siz1 to pos_siz2 - 1 | |
set pos_pos2 to pos_siz1 - 1 | |
set pos_pos1 to pos_pos2 - 1 | |
if (item pos_window_to_activate of prop_window) is "" then -- app Notes | |
tell application "System Events" | |
tell process (item pos_app_to_activate of prop_window) | |
set frontmost to true | |
delay 0.2 | |
click (menu item (item pos_app_to_activate of prop_window) of menu 1 of menu bar item "Window" of menu bar 1) | |
delay 0.8 | |
tell application "System Events" | |
set position of window 1 of process (item pos_app_to_activate of prop_window) to {item pos_pos1 of prop_window, item pos_pos2 of prop_window} | |
delay 1 | |
set size of window 1 of process (item pos_app_to_activate of prop_window) to {item pos_siz1 of prop_window, item pos_siz2 of prop_window} | |
end tell | |
end tell | |
end tell | |
end if | |
if (item pos_window_to_activate of prop_window) is not "" then | |
tell application "System Events" | |
tell process (item pos_app_to_activate of prop_window) | |
set frontmost to true | |
delay 0.05 | |
if (menu item (item pos_window_to_activate of prop_window) of menu 1 of menu bar item "Window" of menu bar 1) exists then | |
click (menu item (item pos_window_to_activate of prop_window) of menu 1 of menu bar item "Window" of menu bar 1) | |
delay 0.8 | |
tell application "System Events" | |
set position of window 1 of process (item pos_app_to_activate of prop_window) to {item pos_pos1 of prop_window, item pos_pos2 of prop_window} | |
delay 1 | |
set size of window 1 of process (item pos_app_to_activate of prop_window) to {item pos_siz1 of prop_window, item pos_siz2 of prop_window} | |
end tell | |
end if | |
end tell | |
end tell | |
end if | |
end repeat | |
tell application "System Events" | |
display notification "Done!" with title "Script 37.1" | |
end tell | |
return | |
else -- of if condition_met is 1 then | |
copy 1 to the end of list_condition_not_met | |
set user_repeat_round to round (user_repeat) | |
if (count list_condition_not_met) is user_repeat_round then | |
display dialog "Condition Not Met. | |
Delete Group and Create Again." with title "Edit Script 37.1" | |
end if | |
end if | |
end repeat -- repeat user_repeat times | |
end if -- (count list_total_condition) is not 0 then | |
if (count list_total_condition) is 0 then | |
set the clipboard to "" | |
set list_target_windows to {} | |
set list_prop_for_window to {} | |
set button_add_stop to "" | |
set num to 0 | |
repeat until button_add_stop is "Stop" | |
tell application "System Events" | |
set add_or_stop to (display dialog "To add window to group, click window and click button 'Add'" buttons {"Add", "Stop"} with title "Script 37.1") | |
end tell | |
delay 1 | |
set button_add_stop to button returned of add_or_stop | |
if button_add_stop is "Add" then | |
-- build code | |
tell application "System Events" | |
set activeApp to (get name of first process where it is frontmost) | |
end tell | |
tell application "System Events" | |
tell process activeApp | |
set mywinName to get title of front window | |
try | |
if mywinName is "" then | |
if activeApp is not "Notes" then | |
tell application "System Events" | |
tell process activeApp | |
delay 0.07 | |
set list_menu_window to name of every menu item of menu 1 of menu bar item "Window" of menu bar 1 | |
end tell | |
end tell | |
tell application "System Events" | |
tell process activeApp | |
repeat with i from 1 to count list_menu_window | |
if (item i of list_menu_window) is not missing value then | |
set myValue to (value of attribute "AXMenuItemMarkChar" of menu item (item i of list_menu_window) of menu 1 of menu bar item "Window" of menu bar 1 as string) | |
delay 0.2 | |
if myValue is "✓" then | |
if activeApp is "soffice" then | |
if (item i of list_menu_window) is not "Freeze" and (item i of list_menu_window) is not "Split" then | |
set mywinName to (item i of list_menu_window) | |
set active_win_exists to 1 | |
exit repeat | |
end if | |
end if | |
else | |
set active_win_exists to 0 | |
end if | |
end if | |
end repeat | |
end tell | |
end tell | |
if active_win_exists is 0 then | |
set mywinName to activeApp | |
end if | |
end if | |
end if | |
end try | |
copy mywinName to the end of list_target_windows | |
end tell | |
end tell | |
tell application "System Events" | |
set ppp to get position of window 1 of process activeApp | |
delay 0.03 | |
set sss to get size of window 1 of process activeApp | |
delay 0.02 | |
set pos1 to (item 1 of ppp) | |
set pos2 to (item 2 of ppp) | |
set siz1 to (item 1 of sss) | |
set siz2 to (item 2 of sss) | |
set num to num + 1 | |
set name_set to "set prop to " | |
set code_for_window to pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & ", " & "\"" & mywinName & "\"" & ", " & "\"" & activeApp & "\"" & "," | |
delay 0.5 | |
copy code_for_window to the end of list_prop_for_window | |
end tell | |
-- end - build code | |
end if -- button_add_stop is "Add" then | |
end repeat -- until button_add_stop is "Stop" | |
if num is not 0 then | |
tell application "System Events" | |
display dialog "Paste Code to Script File." with title "Script 37.1" | |
end tell | |
end if | |
if num is not 0 then | |
set apple_std to text item delimiters | |
set text item delimiters to ", " | |
set out_of_list to list_target_windows as text | |
set text item delimiters to apple_std | |
copy num to the end of list_prop_for_window | |
set the clipboard to "" | |
repeat with i from 1 to count list_prop_for_window | |
set old_c_1 to the clipboard | |
set the clipboard to old_c_1 & (item i of list_prop_for_window) | |
end repeat | |
set old_c_2 to the clipboard | |
set the clipboard to "-- windows: " & out_of_list & " | |
" & "set prop_window to {" & old_c_2 & "} | |
copy 1 to the end of list_total_condition | |
-- END GROUP" | |
end if | |
end if -- (count list_total_condition) is 0 then |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment