Demonstration of how to use an AppleScript Bundle to enable access to NSScreen in AppleScriptObjC
(* | |
Copy and paste this script into a new document in AppleScript Editor. | |
When saving, select "Script Bundle" as File Type. | |
Save the file to: "~/Library/Script Libraries/Access NSScreen.scptd" | |
Note: you may need to create the directory: "~/Library/Script Libraries" | |
Note: while this gist has the file ending "scpt", by selecting the | |
"Script Bundle" file type, the file extension "scptd" should be added. | |
Now, in the document's toolbar in AppleScript Editor click "Bundle Contents" | |
and select "Applescript/Objective-C Library" checkbox | |
Click "Compile" and save again. | |
Now, you can try out the next file ("demo Access NSScreen.scpt") to get the size | |
and layout of your displays. | |
*) | |
use framework "AppKit" | |
on getScreenLayout() | |
set output to {} | |
repeat with curScreen in current application's NSScreen's screens() | |
set theFrame to curScreen's frame() | |
set thisDisplay to {width:width of |size| of theFrame, height:height of |size| of theFrame, originX:x of origin of theFrame, originY:y of origin of theFrame} | |
copy thisDisplay to the end of the output | |
end repeat | |
return output | |
end getScreenLayout |
use theLib : script "Access NSScreen" | |
use scripting additions | |
set theResult to theLib's getScreenLayout() | |
set theString to "" | |
set dispnum to 0 | |
repeat with curDisplay in theResult | |
set theString to theString & "Display " & (dispnum as string) & return | |
set theString to theString & tab & "Size (width, height):" & tab & width of curDisplay & tab & height of curDisplay & return | |
set theString to theString & tab & "Origin (x, y):" & tab & tab & tab & originX of curDisplay & tab & originY of curDisplay & return | |
set dispnum to dispnum + 1 | |
end repeat | |
display dialog theString |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment