Hi,
the subject of this mail might not be very clear, but I'd like to make a project command (like Charilaos proposed here: http:// lists.macromates.com/pipermail/textmate/2005-October/006283.html ) that restarts apache in a complicated way (because all the easy ways do not work for me) and then loads (or reloads) a given test url in the browser (in my case that's Safari atm).
I've come a long way, but still have some small questions:
1. How can a shell variable be used in a osascript oneliner? Currently I have osascript <<APPLESCRIPT tell app "Safari" to open location "$MY_TEST_URL" APPLESCRIPT which is working, beautifully. It opens the url in $MY_TEST_URL in Safari (in the background = without losing the focus in TextMate), and when this page is already opened in a window or a tab it just refreshes that window or tab. But if I try to make it into a oneliner the variable replacement fails: osascript -e 'tell app "Safari" to open location "$IR_LABSITE_TESTURL"'
2. Can a command in one bundle access the support folder of a different bundle? Or can a command from a different bundle be triggered from the current? I'd like to use the apachectlUsingKeychain.sh shell script that comes with the Apache bundle, but is there a way to access that bundle's support folder? Or do I have to copy the script to the support folder of my own bundle?
3. What does the '-ne' in 'if [[ $(ps -xp $PPID|wc -l) -ne 2 ]]; then' do? Inspired and guided by the Relaunch TextMate command in the TextMate bundle, I made the following which works: echo "$PWD" | sudo -S apachectl stop for (( i = 0; i < 50 && $(echo $(ps -ax | grep [h]ttpd | wc -l))
0; i++ )); do
sleep .2; done echo Apache has stopped echo "$PWD" | sudo -S apachectl start for (( i = 0; i < 50 && $(echo $(ps -ax | grep [h]ttpd | wc -l)) < 4; i++ )); do sleep .2; done echo Apache has started again It works in my few tests, but I'm afraid it will fail when it is taking apache too long to stop (or too long to start), so I trying to built in a test, just like in the Relaunch TextMate command. But what does that '-ne 2' stands for?
Thanks, dirk
On 1. Nov 2006, at 17:40, Dirk van Oosterbosch, IR labs wrote:
[...] if I try to make it into a oneliner the variable replacement fails: osascript -e 'tell app "Safari" to open location "$IR_LABSITE_TESTURL"'
In single quotes, the shell does not expand variables. It does it for double quotes, so try instead:
osascript -e "tell app "Safari" to open location "$IR_LABSITE_TESTURL""
- Can a command in one bundle access the support folder of a
different bundle?
Not without a hardcoded path, so basically no.
Or can a command from a different bundle be triggered from the current? I'd like to use the apachectlUsingKeychain.sh shell script that comes with the Apache bundle, but is there a way to access that bundle's support folder? Or do I have to copy the script to the support folder of my own bundle?
I’d recommend copying the script.
- What does the '-ne' in 'if [[ $(ps -xp $PPID|wc -l) -ne 2 ]];
then' do?
You can do ‘man test’ to see what the options do. -ne is “not equal”.
So it runs ps to ask for processors with the process ID being that of our parent ($PPID) which would be TextMate’s. Then it counts the number of matches (wc -l) and sees if that is two.
I guess something simpler would be:
if ps -cp $PPID | grep -sq TextMate; then …
On 1-nov-2006, at 20:15, Allan Odgaard wrote:
[...] if I try to make it into a oneliner the variable replacement fails: osascript -e 'tell app "Safari" to open location "$IR_LABSITE_TESTURL"'
In single quotes, the shell does not expand variables. It does it for double quotes, so try instead: osascript -e "tell app "Safari" to open location "$IR_LABSITE_TESTURL""
Thanks Allan, you're the greatest. that works perfectly.
- What does the '-ne' in 'if [[ $(ps -xp $PPID|wc -l) -ne 2 ]];
then' do?
You can do ‘man test’ to see what the options do. -ne is “not equal”.
Aha, now I see. Thanks. I didn't realize [ stands for test, and that you can just do a 'man test'. Still wondering though what the difference between [ ... ] and [[ ... ]] is, but I guess I'll have to figure that out off-list ;)