I seem to be struggling with the simplest things in AS.
According to the AS docs from Apple, a “file” type can point to a non-existing file. Yet, I can’t get it working the way I want (I am using 10.10.5 in case that matters):
This works:
set f to POSIX file "/Users/xxx/Desktop/nonexisting"
get f --> file "DQ1:Users:xxx:Desktop:nonexisting"
But this does not:
set f to file "DQ1:Users:xxx:Desktop:nonexisting"
Why would the result that I get from the first example not work when I repeat it exactly?
Supposing that the old file specifier is somehow broken on 10.10 and only “POSIX file” works, then how do I do this:
I start with a folder reference such as this:
tell application "Finder"
set dir to item "Desktop" of home
end tell
Now I like to create a file (or POSIX file) reference for a file “nonexisting” in that desktop folder. How? I’ve tried to coerce the folder to text and then append “/nonexisting” to it, and conver that back into a posix file, but I only get errors no matter what I try. Why is this so friggin difficult!
Also, if someone gives a good answer, how about I ask the same on StackOverflow, which is much better suited for Q&A like this, would you be willing to reply there, too?
«class furl» is more an AppleEvent type (typeFileURL to be excactly) rather than AppleScript type. For better supportibility «class furl» is resolved into an file specifier on return. It’s what I (ab)use when returning so called file specifiers from the AppleScript Toolbox command which are in fact «class furl» objects. Not all AppleEvent types are included in AppleScript (like «class utf8» for utf8 encoded strings).
I apologize but I can’t answer to the question : “Why . ?”
I gave the shorter syntax but, if you dislike «class furl» - which is available for several years, you may use this alternate syntax :
set f to POSIX file (POSIX path of "DQ1:Users:xxx:Desktop:nonexisting")
--> file "SSD 500:DQ1:Users:xxx:Desktop:nonexisting"
Don’t worry, I’m aware of path to desktop folder syntax which I use for years, but here, as the goal was to give a syntax for a non existant item I felt useless to build an existing pathname
Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) vendredi 22 avril 2016 15:38:37
Thanks, Yvan, for showing me “POSIX path” - I had not realized that was available as well. Now I found it in the Apple docs, too. I had overlooked that because it was only mentioned under “alias”, which I was not interested in for this specific issue.
But what if the command you’re using the non-existing path with expects a file (as does my scriptable app, incidentally, that’s how I ended up with this problem - I wanted to pass a file to a save command that expects a “file” specifier), when I can’t even construct such a file easily first?
I now have learned some ways, but they were all not obvious to me. I mean, if the save command wants a file, why shouldn’t I be able to first save that file ref in a variable before I pass it to the save command?
Please forget the client side of your scriptable app.
The file type in the sdef file is not the same as the file specifier in the terminology.
The sdef file type is bridged to NSURL and usually can take a HFS string path or an alias and “ if the developer added a few lines “ even a POSIX path on the AppleScript side.
I forgot to comment that.
Look at what we get if we split your instruction in its components.
set f to ((path to desktop folder) & "nonexisting")
--> {alias "SSD 500:Users:userName:Desktop:", "nonexisting"} # Yes, it returns an awful list of two items of different class
set f to f as string
--> "SSD 500:Users:userName:Desktop:nonexisting"
set f to f as «class furl»
--> file "SSD 500:Users:userName:Desktop:nonexisting"
We may easily get rid of the awful list.
set f to (path to desktop folder as string) & "nonexisting"
--> "SSD 500:Users:userName:Desktop:nonexisting" # Yes, this time, no awful list but a clean string
set f to f as «class furl»
--> file "SSD 500:Users:userName:Desktop:nonexisting"
# So, if we concatenate the components in a single instruction :
set f to (path to desktop folder as string) & "nonexisting" as «class furl»
--> file "SSD 500:Users:userName:Desktop:nonexisting"
Yvan KOENIG running El Capitan 10.11.4 in French (VALLAURIS, France) vendredi 22 avril 2016 20:41:23