Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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
Question marked as Best reply

Posted on May 30, 2012 12:25 PM

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'"

3 replies
Question marked as Best reply

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

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 ID.