Created
November 30, 2018 23:06
-
-
Save ccstone/2ad9027de69297cc6ac2e392a9558722 to your computer and use it in GitHub Desktop.
AppleScriptObjC Handler to List a Folder by FURL, Path, or Name
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
------------------------------------------------------------------------------------------- | |
# Auth: Christopher Stone | |
# dCre: 2018/11/30 16:19 | |
# dMod: 2018/11/30 16:52 | |
# Appl: AppleScriptObjC | |
# Task: List a Given Folder as type Furl, type Path, or by Name. | |
# Libs: None | |
# Osax: None | |
# Tags: @Applescript, @Script, @ASObjC, @List, @Folder, @Furl, @Path, @Name | |
------------------------------------------------------------------------------------------- | |
use AppleScript version "2.4" | |
use framework "Foundation" | |
use scripting additions | |
------------------------------------------------------------------------------------------- | |
set targetDir to path to downloads folder | |
set itemFurlList to my listFolder:targetDir returningAs:"furl" | |
set itemPathList to my listFolder:targetDir returningAs:"path" | |
set itemNameList to my listFolder:targetDir returningAs:"name" | |
------------------------------------------------------------------------------------------- | |
--» HANDLERS | |
------------------------------------------------------------------------------------------- | |
on listFolder:targetDir returningAs:returnType -- "furl", "path", "name" | |
set NSDirectoryEnumerationSkipsHiddenFiles to a reference to 4 | |
set NSFileManager to a reference to current application's NSFileManager | |
set {theURLs, theError} to NSFileManager's defaultManager()'s contentsOfDirectoryAtURL:targetDir includingPropertiesForKeys:{} options:(NSDirectoryEnumerationSkipsHiddenFiles) |error|:(reference) | |
if theURLs is equal to missing value then error (theError's localizedDescription() as text) | |
if returnType = "furl" then | |
return theURLs as list | |
else if returnType = "path" then | |
return (theURLs's valueForKey:"path") as list | |
else if returnType = "name" then | |
return (theURLs's valueForKey:"lastPathComponent") as list | |
end if | |
end listFolder:returningAs: | |
------------------------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment