-
-
Save oblitum/b6450e293d07e338179b523803697fcd to your computer and use it in GitHub Desktop.
Demonstration of how to use an AppleScript Bundle to enable access to NSScreen in AppleScriptObjC
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
(* | |
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 |
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
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