Skip to content

Instantly share code, notes, and snippets.

@ccstone
Created November 30, 2018 23:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ccstone/2ad9027de69297cc6ac2e392a9558722 to your computer and use it in GitHub Desktop.
Save ccstone/2ad9027de69297cc6ac2e392a9558722 to your computer and use it in GitHub Desktop.
AppleScriptObjC Handler to List a Folder by FURL, Path, or Name
-------------------------------------------------------------------------------------------
# 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