Slashes in filenames (was: Elementary fie naming question)
Slashes in filenames (was: Elementary fie naming question)
- Subject: Slashes in filenames (was: Elementary fie naming question)
- From: Axel Luttgens <email@hidden>
- Date: Tue, 13 Jan 2004 13:27:55 +0100
The whole matter started with a post from Bernard Azancot, who
encountered problems while trying to save files with names containing
slashes from a 'tell app "Tex-Edit Plus"' script (December 16th).
Marc and Ken suggested to change the slashes into dashes.
I felt somewhat uncomfortable with that workaround, as something deeper
seemed to be at work.
I first reacted to a statement from Ken, but that provoked a thread
through which I was not sure to recognize my own sentences and arguments
anymore, so that I decided to start a new one ;-)
The fact is that there seems to be a globally inconsistent behavior with
regards to slashes in file names.[1]
So, just go to the Finder and put a slash into the name of some item
laying around on the desktop.
No problem: the Finder accepts the slash without complaining, as it has
always done.
The same way, something like:
tell application "Finder"
make new file at desktop with properties {name:"aaa/bbb"}
end tell
--> document file "aaa/bbb" of folder "Desktop"...
Works without problem.
So, you CAN have files with slashes in their names.[2]
But...
Now, let's do:
choose file name
--> [bing bing bing]
Each time you try to enter a slash, you just get a beep.[3]
On the other hand, avoiding the dialog allows to go a lot further:
set f to ("Disks:Users:luttgens:Desktop:aaa/bbb" as <<class furl>>)
set r to open for access f
close access f
As expected, if the file doesn't exist, it is created, otherwhise it is
just accessed.
The same way, if the file already exists, aliases do as well:
set a to alias "Disk:Users:luttgens:Desktop:aaa/bbb"
set r to open for access a
close access a
Once the file exists, you can select it through 'choose file':
choose file
--> alias "Disk:Users:luttgens:Desktop:aaa/bbb"
So, base AppleScript allows you to create or use files with slashes in
their names, with just the restriction noted for 'choose file name'.
What about applications?
Bernard seemed to have problems with something like:
tell application "Tex-Edit Plus"
save window 1 in file "Disk:Users:luttgens:Desktop:aaa/bbb"
end tell
I don't have Tex-Edit+ and thus can't experiment; but it seemed that an
error explicitely occured.
With BBEdit:
tell application "BBEdit"
save window 1 in file "Disk:Users:luttgens:Desktop:aaa/bbb"
--> error: the save location was specified but was invalid
Hmmm. Looks like to behave as Tex-Edit+ does...
Moreover, the "Save as..." dialog in BBEdit disallows you to enter
slashes too. But you can open a file with a slash in its name.
With TextEdit:
tell application "TextEdit"
save document 1 in file "Disk:Users:luttgens:Desktop:aaa/bbb"
end tell
Works. The file is created. [4]
You can also enter slashes in a "Save as..." dialog and save the file.
With Script Editor (yes, why not?):
tell application "Script Editor"
save document 1 in file "Disk:Users:luttgens:Desktop:aaa/bbb"
end tell
Silently fails (no error message, no file created).
Note that you may enter slashes in a "Save as..." dialog, but the save
operation fails.
With Safari:
tell application "Safari"
save window 1 in file "Disk:Users:luttgens:Desktop:aaa/bbb.html"
end tell
Works: the file is created.
Moreover, a "Save as..." in Safari allows you to enter slashes into the
file name and save the file...
Does all the above mean that everybody comes with their own libraries
and conventions?
Or that lots of bugs are kreeping here and there?
Or?
Axel
[1] And please don't come with general aphorisms such as "it is a very
bad idea to put special chars into file names"... It is not my point
here ;-)
[2] As viewed in the Finder. Looking at such files from unix, those
slashes appear as semicolumns; the converse being true too: semicolumns
put in a file's name from the unix layer appear as slashes in the
Finder. And the whole matter is very consistent.
[3] Such a behavior doesn't appear in AS 1.6 or 1.8.3 (MacOS 9): you
just can enter slashes. The older I can test here under MacOS 10 is AS
1.8.3; slashes are forbidden.
[4] But the window title then becomes "aaa:bbb"... You need to close and
reopen the file to get a correctly named window.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.