2

Preface this by saying I will be launching this script whether it be applescript or bash script with Alfred.app.

Sorry to be so blunt and unknowledgable but I need to run a couple lines of bash in an applescript. I think a simple bash script is capable but I do not know for sure. Here are the details (note that the commands should probably be different so if you have suggestions, please feel free to state them as they are probably correct):

I want the script to

  1. rm ~/Library/Vidalia/vidalia.conf'
  2. unzip ~/Library/Vidalia/vidalia.conf.zip'
  3. launch Vidalia.app

Step below I do not believe is possible since the Vidalia.app is not scriptable and I don't want the applescript/bash script to be running until Vidalia quits... but if it's possible to implement without the script needing to stay open:

4) On quit of Vidalia.app rm ~/Library/Vidalia/vidalia.conf

Is this possible. I can use bash or applescript whatever is easiest for you guy's & gals to help me with. If I could get the first three steps to run I would be plenty happy! Thanks for your time and sorry for my lack of knowledge. Any tips or pointers are welcome.

Heck, I don't even know if those are the "proper" shell commands to use, they did the job but if they are "sound" I do not know.

Thank you for your time and patience.

UPDATE - Question: How to move unzipped file into different directory?

Okay I have one last question. How would I do this same sort of action, but I wanted to keep vidalia.conf.zip in another directory?

Say, for example, an external volume named tor - I moved into the mounted volume named tor with pushd, but when I go to extract the file with what I think should work -d I get the error that I cannot create extraction directory

Which is good because I don't want to replace the directory, just move what get's unzipped into the pre-existing directory. Yeah, I will probably have to remove the file already there depending on what I am doing so what I have looks like this...

pushd ~/Library/Vidalia/
rm vidalia.conf
popd
pushd /Volumes/tor
unzip vidalia.conf.zip -d ~/Library/Vidalia/
popd

I haven't quite tried this too much once I ran into the error with plain old -d. As I was typing this I realized that I had to be navigating directories more with pushd and then out with popd. Originally I just had lines 4 and 5 but added the top 3 to remove the .conf that currently is there ... if ... it is there...

Which bring me to one more question… Is it harmless to tell bash to remove a file that doesn't exist? I would have no idea where to even start with if then statements.

Lastly, can anyone recommend a good beginners intro to Bash book? I'd love to actually learn this stuff instead of just having to google and then turn around and bug you all. Thank you again for your help. You solved my earlier problem perfectly, I even learned a lot from the simple example (I think.)

Cheers!

2 Answers 2

3

As @laaph mentioned, if you just want to run bash commands, use a bash script.

There are, however, a few issues with your commands.

Your script has to look like:

#!/bin/sh

pushd ~/Library/Vidalia
rm vidalia.conf
unzip vidalia.conf.zip
popd
open /Applications/Vidalia.app

If you didn't change to the correct directory, unzip would unzip the file into your home directory, or wherever you launched your script from.

There are ways to look for when an app quits, but in your case this seems useless, you're removing the .conf whenever you launch the script anyway. But if you really want that, you could simply do:

#!/bin/sh

pushd ~/Library/Vidalia
rm vidalia.conf
unzip vidalia.conf.zip
popd
open -W /Applications/Vidalia.app
pushd ~/Library/Vidalia
rm vidalia.conf
popd

(This would make the script wait until you close the app, and then it'd delete the configuration file. Again though, this is useless and redundant if you'll be only launching the app with the script.)

Also, you could try a simpler solution: I assume that what you want is just to have the same vidalia.conf whenever you start the program. If that's the case, try just making the .conf read-only.

5
  • As for why I am doing this... I have a vidalia.conf file that is configured to use obfsproxy... which is the .conf I want to unzip. So when I run this script I will be wanting to use that obfsproxy .conf with vidalia. When vidalia quits, I want the obfsproxy .conf which was unzipped for that session to be deleted so I can simply run vidalia without the script and have it create a generic "direct" connect .conf and connect without obfsproxy.
    – Bob Peaks
    Jun 17, 2012 at 5:35
  • Second script with the three extra lines does EXACTLY what I want/need it to do! THANK YOU, THANK YOU, THANK YOU! Amazing, - thanks for taking the time to read the post and respond with a couple of solutions. You have made my day.
    – Bob Peaks
    Jun 17, 2012 at 5:49
  • Quick question. I am a perfectionist which is not good when it comes to this stuff since I have no idea what I am doing with code but do you see any problems with me changing out the line unzip vidalia.conf.zip for unzip vidalia.conf.zip;rm -rf __MACOSX ? I want to avoid creating that empty __MACOSX folder. I haven't noticed a problem but I want to ask since you clearly know what your doing.
    – Bob Peaks
    Jun 17, 2012 at 6:17
  • Yes, adding that is fine. Why not just remove the __MACOSX folder from the zip file though?
    – houbysoft
    Jun 17, 2012 at 11:56
  • One more question for you up top if you have the time. How about unzipping into a different directory so I don't have to clutter the actual Library directory with zipped files? More in depth edit above. As always, thank you, and much appreciated.
    – Bob Peaks
    Jun 18, 2012 at 18:51
1

What you have so far is exactly what you want, and to open a program, use "open", so your script will look like this:

rm ~/Library/Vidalia/vidalia.conf
unzip ~/Library/Vidalia/vidalia.conf.zip
open /Applications/Vidallia.app

There are all sorts of tricks to monitor if Vidalia is running or not, so if you were willing to leave the script running, you could delete the conf as well, and then have the script exit. And, as you say, this could be done (differently) in Applescript, Automator, or a million other ways.

3
  • Although I am going to be honest and say I have found my solution in the script above, I thank you for showing some interest and giving me ideas to run with. Had it not been for houbysoft, I would be using your script and exploring other means, mentioned by you of monitoring if Vidalia was running or not. Thanks for the help.
    – Bob Peaks
    Jun 17, 2012 at 5:54
  • For some reason I don't see the add comment under your post, I am putting it here. <br/> It is harmless to tell bash to move files. It will put an error message to stderr if it can't move the files (which you should be able to see via the Console.app), however. Also there are ways to squelch the error (for example, mv file dest 2> /dev/null) if it bothers you much.
    – laaph
    Jun 18, 2012 at 20:37
  • I appreciate the response but I don't see exactly where this would go. I guess it is much harder than I previously thought to just unzip a file and then move it to a pre-existing directory. Thank you for the help. I will look into this for sure.
    – Bob Peaks
    Jun 19, 2012 at 5:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .