Spaces in path names

Hi,

I am trying to create an applescript that will open the Firefox profile manager so that I can just run the script rather than opening terminal and entering the command each time. Basically Firefox doesn't let you manage profiles like Mozilla throught the tools menu, you have to quit the program and enter the appropriate command into terminal (assuming Firefox.app is in the Applications folder):

/Applications/firefox.app/Contents/MacOS/firefox -profilemanager

In my case i have it in a different folder with the path:

/Applications/Internet\ Applications/Web\ Browsers/Firefox/firefox.app/Contents/MacOS/firefox -profilemanager

I don't know much about scripting, but i know scripts can run UNIX commands using the "do shell script" command. The problem is I don't know how to tell Applescript how to interpret the spaces in the pathname literally, i keep getting an unknown token error. Can someone help me? Here is the script as I have it so far:

do shell script "/Applications/Internet\ Applications/Web\ Browsers/Firefox/firefox.app/Contents/MacOS/firefox -profilemanager "

17" iMac Core Duo, DC 1.83GHz, 512MB RAM, Mac OS X (10.4.6);, iMac G3 500Mhz Snow, 384MB RAM, Mac OS X (10.4.6)

Posted on Aug 27, 2006 7:43 PM

Reply
13 replies

Aug 27, 2006 8:38 PM in response to kel

Thanks Kel,

sorry, I'm still unsure, do I add a "do shell script" command before set u_path etc.? I entered it just as you said and it returns the path in the results box. If I put "do shell script" on a line above this it gives the error "Can't make current application into type string."

If I change the script to this:

do shell script quoted form of "/Applications/Internet Applications/Web Browsers/Firefox/firefox.app/Contents/MacOS/firefox -profilemanager"

it will run but gives the error:

sh: line 1: /Applications/Internet Applications/Web Browsers/Firefox/firefox.app/Contents/MacOS/firefox -profilemanager: No such file or directory

I have checked this path in terminal and it is correct.

I really don't have any clue, so I'm sorry if I'm making simple mistakes

Aug 27, 2006 8:46 PM in response to Ben_

Hi Ben,

My mistake. I think you want this:

set u_path to quoted form of "/Applications/Internet Applications/Web Browsers/Firefox/firefox.app/Contents/MacOS/firefox"
do shell script u_path & " -profilemanager"

I didn't see that -profilemanager was some command. So here, I separated the path from the command.

gl,

Aug 27, 2006 8:49 PM in response to Ben_

If you know that the path will be constant, you can use:

do shell script "'/Applications/Internet Applications/Web Browsers/Firefox/Firefox.app/Contents/MacOS/firefox' -profilemanager"

Since you're passing a parameter to Firefox, you cannot simply place single quotes around the whole string. You need to place the quotes around only the path. If you use single quotes around the whole string, the shell will misinterpret the parameter as part of the path and cause the script to fail.

(15663)

Aug 27, 2006 9:10 PM in response to kel

That's done it, thanks! One last problem though- I have saved the script as an application and it works when I double click on it, but once it opens the profile manager it stays open and stops responding (ie. I have to force quit it). How would I make it quit once it finishes running?

Aug 27, 2006 9:22 PM in response to Ben_

Hi,

What I was thinking is, that you probably want the profilemanager window become frontmost and eventually get the path to the application dynamically. Still trying to figure it out. You can get the path with:

(path to application "Firefox" as string)

but how to bring the window to the front?

gl,

Aug 27, 2006 9:33 PM in response to Ben_

Using a do shell script such as that one will keep the script running until you quit Firefox. If you are looking for a method which doesn't, you can either put it in an application's tell block:

tell application "Finder"
ignoring application responses
set u_path to quoted form of "/Applications/Internet Applications/Web Browsers/Firefox/firefox.app/Contents/MacOS/firefox"
do shell script u_path & " -profilemanager"
end ignoring
end tell

or use the method posted on this page to discard the output. To see it quickly, search the linked page for 'background server'.

(15664)

Aug 28, 2006 7:20 PM in response to Ben_

In the code below 'FireFox.app' was placed onto an internal hard disk drive (HD2), other than the internal boot drive (HD3), the full path being ...

HD2:Demo (folder) [1]:Internet:Web Browsers:Firefox 1.5.0.6:Firefox.app

This in UNIX format translates to ...

/Volumes/HD2/Demo\ \(folder\)\ \[1\]/Internet/Web\ Browsers/FireFox\ 1.5.0.6/Firefox.app/

---

Code 01

set fireFox_Path to "/Volumes/HD2/Demo\\ \\(folder\\)\\ \\[1\\]/Internet/Web\\ Browsers/FireFox\\ 1.5.0.6/Firefox.app/Contents/MacOS/firefox"

do shell script (fireFox_Path & " -profilemanager")

---

Code 02

set fireFox_Path to "/Volumes/HD2/Demo\\ \\(folder\\)\\ \\[1\\]/Internet/Web\\ Browsers/FireFox\\ 1.5.0.6/Firefox.app/Contents/MacOS/firefox" & " -profilemanager"

do shell script fireFox_Path

---

Code 03

do shell script ("/Volumes/HD2/Demo\\ \\(folder\\)\\ \\[1\\]/Internet/Web\\ Browsers/FireFox\\ 1.5.0.6/Firefox.app/Contents/MacOS/firefox" & " -profilemanager")

-----

For a ' ' (space) to exist in a UNIX path - the ' ' (space) must be proceeded by a '\'.
For a '\' to exist in your AppleScript code - the '\' must be proceeded by a '\'.

Thus '\\ ' is needed for each ' ' (space) in your AppleScript code, of a UNIX path.

The same use of '\\' applies to '(', ')', '[', and ']', as well as, many other characters.

Mac OS X (10.4.4)

Aug 29, 2006 9:01 PM in response to Ben_

01. My reply was primarily with respect to 'spaces', and such, in the unix file path.

02. Yes, I saved the code as an AppleScript applet (application), and noticed - when the applet is launched, it remains the front most process; however, the resultant 'Firefox - Choose User Profile' window can be clicked on, to bring it forward. When either the window's 'Exit' button is pressed, or when the 'Start Firefox' button is pressed and eventually 'Firefox' is quitted - only then does the AppleScript applet also quit.

It appears (to me) that the applet goes into 'modeless' mode (or similar), and continues its code execution (if any exists below the 'do shell script' line) and then quits - only on the dismissal of the 'Firefox - Choose User Profile' window, or when 'Firefox' quits.

Mac OS X (10.4.4)

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.

Spaces in path names

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