Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created January 20, 2022 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OKsign/3ae7b96d4a60309138a7ac8b3c7c1774 to your computer and use it in GitHub Desktop.
Save OKsign/3ae7b96d4a60309138a7ac8b3c7c1774 to your computer and use it in GitHub Desktop.
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
delay 0.03
set Replace_Me to "abc"
-- user input (up to 20) - based on active app name
set input1 to Replace_Me
set input2 to Replace_Me
set input3 to Replace_Me
set input4 to Replace_Me
set input5 to Replace_Me
set input6 to Replace_Me
set input7 to Replace_Me
set input8 to Replace_Me
set input9 to Replace_Me
set input10 to Replace_Me
set input11 to Replace_Me
set input12 to Replace_Me
set input13 to Replace_Me
set input14 to Replace_Me
set input15 to Replace_Me
set input16 to Replace_Me
set input17 to Replace_Me
set input18 to Replace_Me
set input19 to Replace_Me
set input20 to Replace_Me
-- end of user input
set nameList to {input1, input2, input3, input4, input5, input6, input7, input8, input9, input10, input11, input12, input13, input14, input15, input16, input17, input18, input19, input20}
delay 0.03
repeat with i from 1 to 20
if (item i of nameList) is not Replace_Me then
if activeApp is item 5 of (item i of nameList) then
-- add fix s14.1
if activeApp is "Google Chrome" then
if item 5 of (item i of nameList) is "Google Chrome" then
tell application "Google Chrome"
set Chrome_winName to get title of front window
end tell
tell application "System Events"
tell process "Google Chrome"
click (menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 2
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of (item i of nameList), item 2 of (item i of nameList)}
delay 1
set size of window 1 of process activeApp to {item 3 of (item i of nameList), item 4 of (item i of nameList)}
end tell
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end if -- item 5 of (item i of nameList) is "Google Chrome"
end if -- activeApp is "Google Chrome"
-- end add fix s14.1
delay 0.02
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of (item i of nameList), item 2 of (item i of nameList)}
delay 1
set size of window 1 of process activeApp to {item 3 of (item i of nameList), item 4 of (item i of nameList)}
return
end tell
else
set GoList to 1
end if -- activeApp is item 5 of (item i of nameList)
else
set GoList to 1
exit repeat
end if -- (item i of nameList) is not Replace_Me
end repeat
if GoList is 1 then -- Choose from list
set Replace_Me to "abc"
-- user input (up to 10 names) - list
set nameList to {"", "", "", "", "", "", "", "", "", ""}
-- user input (up to 10) - list
set SizPos1 to Replace_Me
set SizPos2 to Replace_Me
set SizPos3 to Replace_Me
set SizPos4 to Replace_Me
set SizPos5 to Replace_Me
set SizPos6 to Replace_Me
set SizPos7 to Replace_Me
set SizPos8 to Replace_Me
set SizPos9 to Replace_Me
set SizPos10 to Replace_Me
-- end of user input
set nameList2 to {}
repeat with i from 1 to count nameList
if {nameList's item i} does not contain "" then
set nameList2's end to nameList's item i
end if
end repeat
delay 0.7
set PickName to (choose from list nameList2 with prompt "Set Size and Position to..." with title "Script 14.1")
if PickName is not false then
-- fix add s14.1
if activeApp is "Google Chrome" then
tell application "Google Chrome"
activate
delay 0.2
set Chrome_winName to get title of front window
end tell
tell application "System Events"
keystroke "m" using command down
end tell
delay 2
if (item 1 of PickName) is (item 1 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos1, item 2 of SizPos1}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos1, item 4 of SizPos1}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 2 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos2, item 2 of SizPos2}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos2, item 4 of SizPos2}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 3 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos3, item 2 of SizPos3}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos3, item 4 of SizPos3}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 4 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos4, item 2 of SizPos4}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos4, item 4 of SizPos4}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 5 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos5, item 2 of SizPos5}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos5, item 4 of SizPos5}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 6 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos6, item 2 of SizPos6}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos6, item 4 of SizPos6}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 7 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos7, item 2 of SizPos7}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos7, item 4 of SizPos7}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 8 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos8, item 2 of SizPos8}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos8, item 4 of SizPos8}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 9 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos9, item 2 of SizPos9}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos9, item 4 of SizPos9}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
if (item 1 of PickName) is (item 10 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos10, item 2 of SizPos10}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos10, item 4 of SizPos10}
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
return
end tell
end if
end if -- activeApp is "Google Chrome"
-- end fix add s14.1
delay 0.02
if (item 1 of PickName) is (item 1 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos1, item 2 of SizPos1}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos1, item 4 of SizPos1}
return
end tell
end if
if (item 1 of PickName) is (item 2 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos2, item 2 of SizPos2}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos2, item 4 of SizPos2}
return
end tell
end if
if (item 1 of PickName) is (item 3 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos3, item 2 of SizPos3}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos3, item 4 of SizPos3}
return
end tell
end if
if (item 1 of PickName) is (item 4 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos4, item 2 of SizPos4}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos4, item 4 of SizPos4}
return
end tell
end if
if (item 1 of PickName) is (item 5 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos5, item 2 of SizPos5}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos5, item 4 of SizPos5}
return
end tell
end if
if (item 1 of PickName) is (item 6 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos6, item 2 of SizPos6}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos6, item 4 of SizPos6}
return
end tell
end if
if (item 1 of PickName) is (item 7 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos7, item 2 of SizPos7}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos7, item 4 of SizPos7}
return
end tell
end if
if (item 1 of PickName) is (item 8 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos8, item 2 of SizPos8}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos8, item 4 of SizPos8}
return
end tell
end if
if (item 1 of PickName) is (item 9 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos9, item 2 of SizPos9}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos9, item 4 of SizPos9}
return
end tell
end if
if (item 1 of PickName) is (item 10 of nameList) then
tell application "System Events"
set position of window 1 of process activeApp to {item 1 of SizPos10, item 2 of SizPos10}
delay 1
set size of window 1 of process activeApp to {item 3 of SizPos10, item 4 of SizPos10}
return
end tell
end if
end if -- PickName is not false
set switch to 0
if switch is 1 then
-- script: get size and position of window
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
-- add fix s14.1
if activeApp is "Google Chrome" then
tell application "Google Chrome"
set Chrome_winName to get title of front window
end tell
tell application "System Events"
tell process "Google Chrome"
click (menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 2
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 PosSize to "{" & pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & "}"
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
set the clipboard to PosSize
delay 0.5
display dialog "Done!" with title "Get Size and Position of Window"
end tell
-- end add fix s14.1
else -- activeApp is not "Google Chrome"
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 PosSize to "{" & pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & "}"
delay 1
set the clipboard to PosSize
delay 0.5
display dialog "Done!" with title "Get Size and Position of Window"
end tell
end if -- activeApp is "Google Chrome"
-- end of script: get size and position of window
-- script: Get Active App Name + Size and Position of Window
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
-- add fix s14.1
if activeApp is "Google Chrome" then
tell application "Google Chrome"
set Chrome_winName to get title of front window
end tell
tell application "System Events"
tell process "Google Chrome"
click (menu item "Minimize" of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 2
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 AppPosSize to "{" & pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & ", " & "\"" & activeApp & "\"" & "}"
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
delay 0.2
click (menu item Chrome_winName of menu 1 of menu bar item "Window" of menu bar 1)
end tell
end tell
delay 0.5
set the clipboard to AppPosSize
delay 0.5
display dialog "Done!" with title "Get Active App Name + Size and Position of Window"
end tell
else -- activeApp is not "Google Chrome"
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 AppPosSize to "{" & pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & ", " & "\"" & activeApp & "\"" & "}"
delay 1
set the clipboard to AppPosSize
delay 0.5
display dialog "Done!" with title "Get Active App Name + Size and Position of Window"
end tell
end if
-- end of script: Get Active App Name + Size and Position of Window
end if -- if switch is 1
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment