Skip to content

Instantly share code, notes, and snippets.

@OKsign
Created August 20, 2018 11:38
Show Gist options
  • Save OKsign/555107b93658abaa777e208686e4c344 to your computer and use it in GitHub Desktop.
Save OKsign/555107b93658abaa777e208686e4c344 to your computer and use it in GitHub Desktop.
set Replace_Me to "abc"
-- user input (up to 30) - position, size and name of window
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
set input21 to Replace_Me
set input22 to Replace_Me
set input23 to Replace_Me
set input24 to Replace_Me
set input25 to Replace_Me
set input26 to Replace_Me
set input27 to Replace_Me
set input28 to Replace_Me
set input29 to Replace_Me
set input30 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, input21, input22, input23, input24, input25, input26, input27, input28, input29, input30}
tell application "System Events"
set activeApp to (get name of first process where it is frontmost)
end tell
delay 0.03
tell application "System Events"
tell process activeApp
set frontmost to true
set ActiveWinName to get title of front window
end tell
end tell
repeat with i from 1 to 30
if (item i of nameList) is not Replace_Me then
if ActiveWinName is item 5 of (item i of nameList) then
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 0.03
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
end if -- ActiveWinName is item 5 of (item i of nameList)
end if -- (item i of nameList) is not Replace_Me then
end repeat
set switch to 0
if switch is 1 then
-- script: get name of active window + size and position
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 frontmost to true
set mywinName to get title of front window
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 WinNamePosSize to "{" & pos1 & ", " & pos2 & ", " & siz1 & ", " & siz2 & ", " & "\"" & mywinName & "\"" & "}"
delay 0.5
set the clipboard to WinNamePosSize
delay 0.5
display dialog "Done!" with title "Get Name of Active Window + Size and Position of Window"
end tell
-- end of script: get name of active window + size and position
end if -- switch is 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment