I’m having trouble save a pointer to a folder in the user defaults. The value always returns as a string or an incomplete path.
Here are the exerpt from my code:
set source_folder to choose folder with prompt “Select Source folder:”
make new default entry at end of default entries of user defaults with properties {name:“Source Folder”, contents:“”}
set contents of default entry “Source Folder” of user defaults to source_folder
Later in my code, I have this to retrieve the folder path
set source_folder to contents of default entry “Source Folder” of user defaults
Path is returned as /test/test/test/ but when I try this:
tell application “Finder”
set the item_list to items of the source_folder whose name contains “AB”
end tell
it returns an error that says "Can’t get every item of “/test/test/test/”
You seems to have left out some lines of code that may help better understand the problem, but I’ll assume what I can’t see and go from there. The reason I’m confused is that th line…
set source_folder to choose folder with prompt "Select Source folder:"
--> Returns: "Macintosh HD:Users:jed:Desktop:Test:"
… returns a colon-delimited path, not the slash-delimited (posix) path you posted. So, if you’ve got a posix-style path then there must be some other code operating on the path to make it that way. Somthing like this is what I used to get the path formatted as you’ve posted…
set source_folder to (POSIX path of (choose folder with prompt "Select Source folder:")) as string
--> Returns: "/Users/jed/Desktop/Test/"
Then, to get the finder to recognize ths posix path as extracted from the string I set above, I used the following…
tell application "Finder"
set the item_list to items of the ((POSIX file source_folder) as alias) whose name contains "AB"
end tell
When I first typed it out I was getting a colon separated path. However, somewhere in my troubleshooting the result became a slash separated path. Anyhow, I just added this line to my code and everything worked correctly:
set source_folder to ((POSIX file source_folder) as alias)
Thank you very much for your help. You saved me a great deal of time. I have only been playing with Applescript for about a month.