Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 11, 2012, 03:59 AM   #1
Let's Sekuhara!
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
Quit Terminal without quitting process? / Multiple simultaneous Firefox profiles

Hi, I'd like to know how I can start a process via command line that is not a child of the app used to invoke the command.

For example if I open Terminal and enter:
Code:
/Applications/Firefox.app/Contents/MacOS/firefox -P "ProfileName"
It will run that Firefox profile, but only as long as I keep Terminal open.

Also tried creating an app bundle in AppleScript Editor, like so:
Code:
do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P \"ProfileName\""
This is less annoying, but still requires the launcher app to remain open alongside Firefox.

Any ideas?
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason

Last edited by Let's Sekuhara!; Dec 14, 2012 at 10:07 AM. Reason: Changed thread title
Let's Sekuhara! is offline   0 Reply With Quote
Old Dec 11, 2012, 04:54 AM   #2
toptan
macrumors newbie
 
Join Date: Sep 2010
Location: Novi Sad, Serbia
I use nohup for stuff like that.

Code:
nohup /Applications/Firefox.app/Contents/MacOS/firefox -P "ProfileName"
The annoying thing is that you have to close terminal manually.
toptan is offline   0 Reply With Quote
Old Dec 11, 2012, 05:17 AM   #3
Let's Sekuhara!
Thread Starter
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
Quote:
Originally Posted by toptan View Post
I use nohup for stuff like that.

Code:
nohup /Applications/Firefox.app/Contents/MacOS/firefox -P "ProfileName"
The annoying thing is that you have to close terminal manually.
Thank you!

I'm looking into whether I can (if I use the AppleScript approach) have the script quit itself after sending the shell script...
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason
Let's Sekuhara! is offline   0 Reply With Quote
Old Dec 11, 2012, 05:31 AM   #4
Let's Sekuhara!
Thread Starter
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
There is a command
Code:
tell me to quit
that is supposed to make the running AppleScript quit itself.
But I just tried writing it into my app and it doesn't work.
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason
Let's Sekuhara! is offline   0 Reply With Quote
Old Dec 11, 2012, 10:36 AM   #5
talmy
macrumors 68040
 
talmy's Avatar
 
Join Date: Oct 2009
Location: Oregon
Quote:
Originally Posted by toptan View Post
I use nohup for stuff like that.

Code:
nohup /Applications/Firefox.app/Contents/MacOS/firefox -P "ProfileName"
The annoying thing is that you have to close terminal manually.
You can also just put an ampersand (&) at the end of the line to run the process in the background. To close the terminal application you can execute killall Terminal assuming you have just one. Otherwise it's a fairly involved process -- get the process id of the bash shell, find it's parent process (a login process), and find the parent process of the login, which is the Terminal, which can then be killed.
__________________
27" i7 iMac, 15" MacBook Pro, Mac mini with Mavericks Server, 5 other Macs and an unused Apple TV.
talmy is offline   0 Reply With Quote
Old Dec 11, 2012, 03:52 PM   #6
Let's Sekuhara!
Thread Starter
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
Quote:
Originally Posted by talmy View Post
You can also just put an ampersand (&) at the end of the line to run the process in the background. To close the terminal application you can execute killall Terminal assuming you have just one. Otherwise it's a fairly involved process -- get the process id of the bash shell, find it's parent process (a login process), and find the parent process of the login, which is the Terminal, which can then be killed.
If I want the process to run the same as a regular instance of Firefox (a process under my user, I suppose) then what would I type?
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason
Let's Sekuhara! is offline   0 Reply With Quote
Old Dec 11, 2012, 05:57 PM   #7
talmy
macrumors 68040
 
talmy's Avatar
 
Join Date: Oct 2009
Location: Oregon
Well I just realized that when you close the Terminal application it kills the login and the copy of Firefox goes away (hence the suggestion to use nohup).
However if you run Firefox from an xterm window (which doesn't do a login) or from an Automator Shell Script then using & works fine and the bash shell can exit with no problems.

Also, you can run Firefox using the Open command: "open /Applications/Firefox.app &"
__________________
27" i7 iMac, 15" MacBook Pro, Mac mini with Mavericks Server, 5 other Macs and an unused Apple TV.
talmy is offline   0 Reply With Quote
Old Dec 11, 2012, 10:13 PM   #8
Let's Sekuhara!
Thread Starter
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
Quote:
Originally Posted by talmy View Post
However if you run Firefox from an xterm window (which doesn't do a login) or from an Automator Shell Script then using & works fine and the bash shell can exit with no problems.
Problem is, then the Automator script app has to remain open for the duration of the session. And that's almost equally annoying as having to keep Terminal open.
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason
Let's Sekuhara! is offline   0 Reply With Quote
Old Dec 12, 2012, 06:35 AM   #9
pitaya
macrumors member
 
Join Date: Jun 2012
Try setting the Terminal.app preference "When the shell exits:" to "Close the window" or "close if the shell exited cleanly". It's under the shell tab in settings.
pitaya is offline   0 Reply With Quote
Old Dec 12, 2012, 09:36 AM   #10
talmy
macrumors 68040
 
talmy's Avatar
 
Join Date: Oct 2009
Location: Oregon
I just discovered that the Terminal app can bypass the login process (it's a preference selection -- just have it run bash directly). Putting all of this together:
1. Change Terminal app preferences to start bash and not do a login.
2. Change Terminal app preferences to close the window when the shell exits.
3. Run Firefox: "open /Applications/Firefox.app &"
4. Exit the terminal window ("exit" command or Control-D).

Firefox will continue to run and Terminal window closes.

BTW, I just double-checked and when run from an Automator script automator will exit when the script is run.
Attached Thumbnails
Click image for larger version

Name:	Untitled.app.jpg
Views:	23
Size:	136.7 KB
ID:	383077  
__________________
27" i7 iMac, 15" MacBook Pro, Mac mini with Mavericks Server, 5 other Macs and an unused Apple TV.
talmy is offline   0 Reply With Quote
Old Dec 12, 2012, 01:14 PM   #11
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by talmy View Post
I just discovered that the Terminal app can bypass the login process (it's a preference selection -- just have it run bash directly). Putting all of this together:
1. Change Terminal app preferences to start bash and not do a login.
2. Change Terminal app preferences to close the window when the shell exits.
3. Run Firefox: "open /Applications/Firefox.app &"
4. Exit the terminal window ("exit" command or Control-D).

Firefox will continue to run and Terminal window closes.

BTW, I just double-checked and when run from an Automator script automator will exit when the script is run.
No trailing '&' should be needed. The 'open' command isn't the parent process of the app it opens. The per-user launchd process is. You can use Activity Monitor to show this: select the program in the list, click Info, observe the parent process.

Also, the Automator example shown shouldn't need any Terminal preferences changes, because it's not running the shell script in Terminal. Even if Terminal is running, it doesn't run the shell script through Terminal. I don't question that the Terminal preferences changes affect Terminal windows. I only question the relevance of those changes to a Run Shell Script action in Automator. The Automator script shown should run Firefox without needing any Terminal preferences changes at all.

When referring to an app to open, using a bundle-name is better than using an absolute path, because it doesn't require the app to be installed at a specific location. The bundle-name string is identical to the CFBundleName item in the app's Info.plist. The option for 'open' is -b. The bundle-name of Firefox is org.mozilla.firefox. So a suitable command-line should be:
Code:
open -b org.mozilla.firefox
Read 'man open' for all command-line options.

Finally, the 'open' commands posted so far have neglected the -P "ProfileName". I presume this is a critical requirement, since otherwise simply double-clicking Firefox would have the same result. In other words, the OP wants to open Firefox with a specific profile, to do so by double-clicking a Finder icon (rather than needing a direct command-line), and to not need a Terminal window or other app to remain open to keep Firefox alive. Assuming those are the requirements, the following should work:
Code:
open -b org.mozilla.firefox --args -P "ProfileName"
This single line should be pasted into a Run Shell Script action in Automator, and saved as an Application. The Run Shell Script action is located under Utilities in the Library of Actions in Automator.

Once saved as an application in Automator, double-clicking it should launch Firefox with the named profile. It will NOT relaunch Firefox if it's already running, nor will it tell an already-running Firefox to change its profile.

I don't have Firefox, so I can't test this completely. However, I tested the above with Safari's bundle name and it worked. It's not necessary to change Terminal preferences, to use nohup, or to use a trailing &.
chown33 is offline   0 Reply With Quote
Old Dec 14, 2012, 09:02 AM   #12
Let's Sekuhara!
Thread Starter
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
Quote:
Originally Posted by chown33 View Post
...In other words, the OP wants to open Firefox with a specific profile, to do so by double-clicking a Finder icon (rather than needing a direct command-line), and to not need a Terminal window or other app to remain open to keep Firefox alive. Assuming those are the requirements, the following should work:
Code:
open -b org.mozilla.firefox --args -P "ProfileName"
This single line should be pasted into a Run Shell Script action in Automator, and saved as an Application. The Run Shell Script action is located under Utilities in the Library of Actions in Automator.
Thank you for the detailed info!
I did everything you described and it works to launch the correct profile, but only if Firefox is not already open (as you stated)...
The majority of the time I want to launch FF with a secondary profile, it's when I currently have my primary one open. So I'm back to square one.

However, I had a thought: What does FF Profile Manager do differently that allows it to launch a secondary instance of FF? And how can I trigger the same process through command line? Hmmm...
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason
Let's Sekuhara! is offline   0 Reply With Quote
Old Dec 14, 2012, 09:51 AM   #13
Let's Sekuhara!
Thread Starter
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
Got it!!! This works:
Code:
/Applications/Firefox.app/Contents/MacOS/firefox-bin -P PrimaryProfile
And the additional profiles should have -no-remote at the end. I don't know why, but I read this somewhere.
Code:
/Applications/Firefox.app/Contents/MacOS/firefox-bin -P SecondaryProfile -no-remote
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason
Let's Sekuhara! is offline   0 Reply With Quote
Old Dec 14, 2012, 09:55 AM   #14
talmy
macrumors 68040
 
talmy's Avatar
 
Join Date: Oct 2009
Location: Oregon
Looks like you could also do:
Code:
open -n -b org.mozilla.firefox --args -P "ProfileName"
which will open a new instance of the application.
__________________
27" i7 iMac, 15" MacBook Pro, Mac mini with Mavericks Server, 5 other Macs and an unused Apple TV.
talmy is offline   0 Reply With Quote
Old Dec 14, 2012, 10:05 AM   #15
Let's Sekuhara!
Thread Starter
macrumors 6502
 
Join Date: Jun 2008
Location: 日本
Quote:
Originally Posted by talmy View Post
Looks like you could also do:
Code:
open -n -b org.mozilla.firefox --args -P "ProfileName"
which will open a new instance of the application.
Good to know. Thanks.

On another topic, I want to know if the application icon can somehow be changed (in order to differentiate when tabbing through apps).
If anyone has made this work on a Mac I'd love to hear how.
Duplicating Firefox.app and changing the icon of one is not a solution. The two copies conflict and cause a crash.
__________________
27" i7 iMac | 11" MacBook Air | Black MacBook | iPhone 5
Favorite Mac apps: Blender | Ableton Live | Reason
Let's Sekuhara! is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: Terminal cannot force quit Chrome bobfitz14 Mac Applications and Mac App Store 1 Apr 30, 2014 04:07 PM
Cannot Force Quit WebEx process (nor can I find it) Praxis91 Mac Basics and Help 7 Apr 28, 2014 12:00 PM
One mini, multiple simultaneous users... Oujmik Mac mini 20 Oct 31, 2013 06:41 AM
Terminal command for quitting applications? RedCroissant Mac Basics and Help 10 Feb 12, 2013 01:24 PM
Quitting the partitioning process forcefully + Missing Space ?! transblack MacBook Pro 1 Sep 1, 2012 04:10 PM

Forum Jump

All times are GMT -5. The time now is 02:02 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC