Applescript: How to reference to a filename with forward slash character?

Hi,


I have this script line:


do shell script "lpadmin -p CIN-East-Copier -E -v lpd://192.168.51.78 -P '/Library/Printers/PPDs/Contents/Resources/LANIER MP C5501/LD655C'"


The filename is "LANIER MP C5501/LD655C", the forward slash in the name is a character, not a folder structure.


The script above works perfectly for drivers without the forward character. Can anyone help me how to make it work? I tried replacing the forward slash with URL encoded character, changing the structure to colon delimited (i.e. Macintosh HD:Library:Printers....etc), none work.


Thanks!

Posted on May 30, 2012 10:04 AM

Reply
3 replies

May 30, 2012 12:25 PM in response to dmdw

Since the / is the standard directory delimiter, it is not usually valid in a filename. It's extremely unusual to find such a character in a filename. However, all is not lost... there is a trick.


Since the standard Mac OS paths used colon-delimited paths, and UNIX uses slash-delimited, there is a kind of hybrid solution... you can use the colon in the shell and it interprets as a slash, e.g.:


do shell script "lpadmin -p CIN-East-Copier -E -v lpd://192.168.51.78 -P '/Library/Printers/PPDs/Contents/Resources/LANIER MP C5501:LD655C'"


I haven't tried it, but you might need to escape (with a backslash) the colon:


do shell script "lpadmin -p CIN-East-Copier -E -v lpd://192.168.51.78 -P '/Library/Printers/PPDs/Contents/Resources/LANIER MP C5501\\:LD655C'"

May 31, 2012 7:15 PM in response to dmdw

In unix the forward slash / is used as the path separator.


In the application layer of Mac OS X, the colon : is used as the path separator.


The forward slash as seen in the application layer is translated to the colon for the unix layer. The colon in the Unix layer gets translated to the forward slash in the application layer.


Depending on where you are seeing the /, you may want to use the : in the name you are referencing for a Unix / terminal command.


Perhaps you are seeing the slash in a Gui display. It would be the : in a Unix display.


Robert

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript: How to reference to a filename with forward slash character?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.