Last active
March 7, 2021 21:57
-
-
Save ChristoferK/adcd3f6a8de9eb1ab2bbf859f90cfacf to your computer and use it in GitHub Desktop.
[Machine Device Icon] Returns a path to a PNG image file containing a hi-resolution representation of the user's machine #AppleScript #AppleScriptObjC #device #computer #machine #icon #NSWorkspace #PNG
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
use framework "Foundation" | |
use framework "AppKit" | |
use scripting additions | |
property this : a reference to the current application | |
property nil : a reference to missing value | |
property _1 : a reference to reference | |
property NSWorkspace : a reference to NSWorkspace of this | |
property NSPNGFileType : a reference to 4 | |
property version : "1.0" | |
property folder : a reference to system attribute "TMPDIR" | |
property filename : "machine.png" | |
property path : a reference to {my folder, my filename} | |
property file : a reference to the POSIX file named (a reference to path) | |
property text item delimiters : "/" | |
tell ((NSWorkspace's sharedWorkspace()'s iconForFileType:"'root'")'s ¬ | |
representations()'s sortedArrayUsingSelector:"size") to if ¬ | |
|count|() > 0 then tell ((the firstObject()'s ¬ | |
representationUsingType:NSPNGFileType |properties|:nil)'s ¬ | |
writeToURL:(my file as «class furl») atomically:yes) ¬ | |
to if it = true then return the POSIX path of my file | |
false |
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
use framework "Foundation" | |
use framework "AppKit" | |
use scripting additions | |
property this : a reference to the current application | |
property nil : a reference to missing value | |
property _1 : a reference to reference | |
property NSWorkspace : a reference to NSWorkspace of this | |
property version : "1.0b" | |
property folder : a reference to system attribute "TMPDIR" | |
property filename : "machine.png" | |
property path : a reference to {my folder, my filename} | |
property file : a reference to the POSIX file named (a reference to path) | |
property text item delimiters : "/" | |
tell ((NSWorkspace's sharedWorkspace()'s iconForFileType:"'root'")'s ¬ | |
TIFFRepresentation()'s writeToURL:(my file as «class furl») ¬ | |
atomically:yes) to if it = true then tell my file to return ¬ | |
the PNG(POSIX path) of me | |
false | |
to PNG(filepath) | |
tell application "Image Events" | |
set _img to open filepath | |
set _PNG to save _img as PNG in filepath with icon | |
return the _PNG's POSIX path | |
end tell | |
end PNG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment