Created
January 20, 2022 11:36
-
-
Save OKsign/7d7a97c8217cdc0ee8694ab1c1f62ef9 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
-- user options | |
set create_group to "off" -- "on" or "off" | |
-- end of user options --------------------------------- | |
-- get name of all windows | |
if create_group is "off" then | |
set list_all_windows to {} | |
tell application "System Events" | |
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 | |
---------------------------------------------------------------------- | |
-- PASTE BELOW. | |
-- END - PASTE BELOW | |
---------------------------------------------------------------------- | |
if (count list_done) is 0 then | |
display dialog "Condition Not Met." with title "Edit Script 36.2" | |
end if | |
end if -- if create_group is "off" then | |
-- end - get name of all windows | |
if create_group is "on" 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 36.2") | |
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 | |
-- fix - s36.1 | |
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 | |
-- fix - s36.1 - 2 ifs | |
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 | |
-- end - fix - s36.1 - 2 ifs | |
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 | |
-- end - fix - s36.1 | |
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 | |
end repeat | |
if num is not 0 then | |
tell application "System Events" | |
display dialog "Paste Code to Script File." with title "Script 36.2" | |
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 & "} | |
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\" | |
set next_or_stop to (display dialog \"Next or Stop?\" buttons {\"Next\", \"Stop\"} with title \"Script 36.2\") | |
end tell | |
set button_next_stop to button returned of next_or_stop | |
if button_next_stop is \"Stop\" then | |
return | |
end if | |
end if | |
-- END - GROUP" | |
end if | |
end if -- if create_group is "on" then |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment