Last active
April 12, 2017 23:24
-
-
Save shanecelis/1457c84ac173c1e271af4194501b5e23 to your computer and use it in GitHub Desktop.
Resize Unity game window to specified size modulo its header
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
-- Resize Unity Game Window to specified size modulo its header | |
-- | |
-- Modified by Shane Celis @shanecelis based off Paul Calnan's script: | |
-- http://www.paulcalnan.com/archives/2014/10/quicktime-screen-recording-of-a-single-window.html | |
-- clickdrag gist at https://gist.github.com/shanecelis/f0754fbd7d9126b18f83966cd538567b | |
-- XXX Set Unity's desired size here: | |
set desiredSize to {300, 300} | |
set theProcessName to "Unity" | |
set theWindowNumber to 1 | |
set controlsHeader to 39 | |
tell application "System Events" | |
tell process theProcessName | |
activate | |
tell window theWindowNumber | |
set thePosition to position | |
set theSize to size | |
end tell | |
end tell | |
end tell | |
set bottomRight to sub(add(thePosition, theSize), {10, 10}) | |
set delta to neg(sub(theSize, add({0, controlsHeader}, desiredSize))) | |
set noteNegatives to "" | |
-- So sending negative integers thru the command line is difficult for swift. | |
if item 1 of delta < 0 then | |
set noteNegatives to noteNegatives & " -negdx true" | |
end if | |
if item 2 of delta < 0 then | |
set noteNegatives to noteNegatives & " -negdy true" | |
end if | |
tell application "Unity" to activate | |
do shell script "~/bin/clickdrag -x " & (item 1 of bottomRight) & " -y " & (item 2 of bottomRight) & " -dx " & abs(item 1 of delta) & " -dy " & abs(item 2 of delta) & noteNegatives | |
on add(a, b) | |
return {(item 1 of a) + (item 1 of b), (item 2 of a) + (item 2 of b)} | |
end add | |
on abs(a) | |
if a < 0 then | |
return -a | |
else | |
return a | |
end if | |
end abs | |
on pr(v) | |
return "(" & (item 1 of v) & ", " & (item 2 of v) & ")" | |
end pr | |
on sub(a, b) | |
return add(a, neg(b)) | |
end sub | |
on neg(a) | |
return {-(item 1 of a), -(item 2 of a)} | |
end neg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment