PDA

View Full Version : Quick AppleScript Question




edesignuk
Jan 29, 2008, 01:43 AM
What I'm trying to do:
Launch Firefox's profile manager.

How I'm doing it:
Well, to run profile manager from a terminal window you enter:/Applications/Firefox.app/Contents/MacOS/firefox -ProfileManagerI had a google round and the best way to do this is from an AppleScript (saved as "Application Bundle") containing the following:do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -ProfileManager"The problem:
The AppleScript app launches fine and runs Firefox's profile manager, the problem is the AppleScript app doesn't exit and actually stops responding.

How do I get the AppleScript to exit cleanly after launching Firefox?

It must be simple, I'm just utterly clueless when it comes to AppleScript :confused: :o

Thanks!



macfaninpdx
Jan 29, 2008, 11:28 AM
When you execute a shell script from Applescript, the script will wait for the output of your shell command before continuing. Since there is no output from the shell command you are executing in your case, the script will wait until you quit the Profile Manager before continuing.

You could add an ampersand to run the shell command in the background. As soon as the command is executed, the script will continue to run without waiting for any output. If this is the last line of your script, it will exit.
do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -ProfileManager &"
There is some good info on the do shell command here (http://developer.apple.com/technotes/tn2002/tn2065.html).

You could also try to just activate the program from Applescript without using a shell command, although this won't launch it with the -ProfileManager switch.
tell application "Firefox" to activate


And finally, see if Firefox has a scripting dictionary. If it does, you may be able to access some features directly from your script, without using a shell command.

edesignuk
Jan 30, 2008, 02:00 AM
You're a genius! The first bit you mentioned putting the "&" at the end worked perfectly. Thank you so much :)

hmmmm, OK, next part of the problem :o

The script to launch the Profile Manager works perfectly as I said. Now to launch in to a specific profile the AppleScript app still hangs.do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P edesignuk &"Firefox does launch in to the profile I want, but the script sits there in a not responding state.

macfaninpdx
Jan 30, 2008, 10:44 AM
You're a genius!:o Tell that to my wife, please.
The script to launch the Profile Manager works perfectly as I said. Now to launch in to a specific profile the AppleScript app still hangs.do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P edesignuk &"Firefox does launch in to the profile I want, but the script sits there in a not responding state.

Now methinks you should also send the stdout and stderr to /dev/null so it is not waiting for any pipes there, either. Try adding "> /dev/null 2>&1" to your line (like this):
do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P edesignuk > /dev/null 2>&1 &"

FYI, "2>&1" combines the stdout and stderr into one, since do shell script keeps them separate. And FWIW, I believe the above statement "> /dev/null 2>&1" is the same as just using "&> /dev/null", so for S&G you could try:
do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P edesignuk &> /dev/null &"

edesignuk
Jan 31, 2008, 01:58 AM
Once again, you're a genius. Works perfectly. Thanks very much again.

techmonkey
Dec 8, 2008, 04:14 PM
old thread but it helped me out today. Im curious though what the syntax actually means

&> /dev/null &

Can someone explain what it means and is doing at the end of the script? Im learning :)

lee1210
Dec 8, 2008, 04:43 PM
> at the end of a command means "redirect the standard out of this command to..." and the filename afterwards is where the output goes
2> means the same, but for the standard error instead of standard output.
&1 used after this means to direct standard error to standard output

& at the end of all of that means to run the command in the background, so it will run (forever if the command does not terminate) out of the way of the program/shell/etc. that launched it. If you did this from a shell, the fg command would bring this program back to the foreground.

/dev/null is a file that is a black hole. You can send as much data there as you'd like, and it will be eaten up, never to be seen again. This is often used when the output of something is unimportant and needs to be discarded.

-Lee

techmonkey
Dec 8, 2008, 05:58 PM
> at the end of a command means "redirect the standard out of this command to..." and the filename afterwards is where the output goes
2> means the same, but for the standard error instead of standard output.
&1 used after this means to direct standard error to standard output

& at the end of all of that means to run the command in the background, so it will run (forever if the command does not terminate) out of the way of the program/shell/etc. that launched it. If you did this from a shell, the fg command would bring this program back to the foreground.

/dev/null is a file that is a black hole. You can send as much data there as you'd like, and it will be eaten up, never to be seen again. This is often used when the output of something is unimportant and needs to be discarded.

-Lee

Thanks for taking to time to explain. Does memory get used up if you send data to /dev/null ?

lee1210
Dec 8, 2008, 06:39 PM
Thanks for taking to time to explain. Does memory get used up if you send data to /dev/null ?

None. Unlike real physics, data can be destroyed by the black hole that is /dev/null.

-Lee

edesignuk
Aug 29, 2009, 03:39 AM
Snow Leopard has now broken this :(

191049

do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P edesignuk &> /dev/null & "

Can anyone help? Pwease! :o :)

edesignuk
Aug 31, 2009, 03:13 AM
Trying to figure this out...

Doesn't look like it's the AppleScript app that's the problem as such, even running the command in Terminal produces the same result (which makes sense I suppose):
/Applications/Firefox.app/Contents/MacOS/firefox -P edesignuk

Here is the crash report:
Process: firefox-bin [1241]
Path: /Applications/Firefox.app/Contents/MacOS/firefox-bin
Identifier: firefox-bin
Version: ??? (???)
Code Type: X86 (Native)
Parent Process: sh [1237]

Date/Time: 2009-08-31 09:08:09.079 +0100
OS Version: Mac OS X 10.6 (10A432)
Report Version: 6

Interval Since Last Report: 34175 sec
Crashes Since Last Report: 7
Per-App Crashes Since Last Report: 5
Anonymous UUID: 9C9A829A-4598-42D4-8B73-E4AB8B3809B6

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0

Dyld Error Message:
Library not loaded: /usr/lib/libsqlite3.dylib
Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
Reason: Incompatible library version: Security requires version 9.0.0 or later, but libsqlite3.dylib provides version 1.0.0

Model: MacPro3,1, BootROM MP31.006C.B05, 8 processors, Quad-Core Intel Xeon, 2.8 GHz, 6 GB, SMC 1.25f4
Graphics: ATI Radeon HD 2600 XT, ATI Radeon HD 2600, PCIe, 256 MB
Memory Module: global_name
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x88), Broadcom BCM43xx 1.0 (5.10.91.19)
Bluetooth: Version 2.2.0f18, 2 service, 0 devices, 1 incoming serial ports
Network Service: AirPort, AirPort, en2
PCI Card: ATI Radeon HD 2600, Display, Slot-1
Serial ATA Device: WDC WD6400AAKS-00A7B2, 596.17 GB
Serial ATA Device: SAMSUNG HD753LJ, 698.64 GB
Serial ATA Device: SAMSUNG HD753LJ, 698.64 GB
Serial ATA Device: WDC WD3200AAJS-41VWA0, 298.09 GB
Parallel ATA Device: PIONEER DVD-RW DVR-112D
USB Device: Keyboard Hub, 0x05ac (Apple Inc.), 0x1006, 0xfd500000
USB Device: USB/PS2 Wheel Mouse, 0x047d (Kensington), 0x1012, 0xfd530000
USB Device: Apple Keyboard, 0x05ac (Apple Inc.), 0x0221, 0xfd520000
USB Device: USB Receiver, 0x046d (Logitech Inc.), 0xc50e, 0x3d200000
USB Device: Bluetooth USB Host Controller, 0x05ac (Apple Inc.), 0x8206, 0x5d200000
FireWire Device: built-in_hub, Up to 800 Mb/sec
The bit I have bolded looks to be the significant bit.

Is there anything I can do about this? Reeeeeally missing the ability to have multiple Firefox's running with different profiles at once :o

mufflon
Aug 31, 2009, 08:35 AM
Wouldn't a much simpler solution be to simply use automator? You can execute most applications - and failing that you can simply call firefox from the shell - which automator can do as well.

I can elaborate on this later if you want (kind of at work atm :o )

edesignuk
Aug 31, 2009, 01:41 PM
^ It wasn't the AppleScript that was the problem, so I don't really see how Automater would have helped.


Anyway, on searching I found a bug thread at Mozilla (https://support.mozilla.com/tiki-view_forum_thread.php?forumId=1&comments_parentId=432894) about this.

A user there suggested invoking firefox-bin directly rather than just firefox, and it works!

So, doesn't work...
do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P edesignuk &> /dev/null & "
Works...
do shell script "/Applications/Firefox.app/Contents/MacOS/firefox-bin -P edesignuk &> /dev/null & "

macfaninpdx
Sep 1, 2009, 05:14 PM
I'm glad you got it working. ;) This is probably not the last thing we'll find to be broken by Snow Leopard, either.

Cheers.

edesignuk
Sep 2, 2009, 02:26 AM
I'm glad you got it working. ;) This is probably not the last thing we'll find to be broken by Snow Leopard, either.

Cheers.Hi! Thanks for coming and taking a look, but yes, I have it fixed now, nothing to do with AppleScript at all in the end :)

`lowell`
Sep 2, 2009, 02:43 AM
.