0
1
Ok, so I have this great little function in my bash_profile which works great when I call it from Terminal (it opens a new firefox window instead of new tab):
function firefoxNewWindow() {
/usr/bin/env osascript <<-EOF
tell application "System Events"
if (name of processes) contains "Firefox" then
tell application "Firefox" to activate
keystroke "n" using command down
else
tell application "Firefox" to activate
end if
end tell
EOF
}
Now I create a text file and place it on my OSX Lion desktop with a .command extension (firefoxNewWindow.command), and put this text in it:
firefoxNewWindow
I then make sure it is executable by doing this:
chmod a+x desktop/firefoxNewWindow.command
Now when I double-click the command file on the desktop to run it I get this error:
~ >/Users/myname/Desktop/firefoxNewWindow.command ; exit;
/Users/myname/Desktop/firefoxNewWindow.command: line 1: firefoxNewWindow: command not found
logout
So why am I getting a Command Not Found when the function is in the bash_profile and it works from Terminal prompt? Since this is a function in bash_profile I am assuming that no path needs to be specified as it should run from any path. Any ideas on how to make this work?
Thanks


>If I create a text file with something simple like
What other command can I put in bash_profile? Since all the commands are already available at Terminal prompt, not sure I understand what I am supposed to do.
I will try automator idea and see how that works. Thanks
< – jsherk – 2012-03-05T23:17:36.980
lsin it and then add .command extension and make it executable, then it will run fine when I double-click it.What I mean is, for example, put the command
envinto your./bash_profilefile. You can see the environment variables being listed when you call your custom.commandfile – just as a proof./bash_profileis being sourced. I don't know why functions aren't available though. – slhck – 2012-03-06T08:04:54.753Ok I see... when I add
envto bash_profile and run source and then run the .command file from desktop, it does indeed display/run the env command just fine but when it gets to the function it still says command not found. – jsherk – 2012-03-06T15:43:47.893Exactly. That's what I don't get. But if you just want to achieve the Firefox thing, the Automator action will just work fine. I use similar stuff all the time. – slhck – 2012-03-06T15:47:21.330
I did the automator thing and that works great! To summarize: Start Automator, choose new Application and then drag the Run Applescript Action over to the right hand side and then copy and paste your applescript into it and save it as application. You now have an application that runs just as fast as the original applescript, and you can also create an alias on your desktop to it. – jsherk – 2012-03-08T05:43:57.230