Applescript to run terminal command then open application..

Hey,
I've installed the add-on to make the Lion Finder sidebar icons colored again, but whenever I reboot my Mac, I have to execute a killall Finder to get those icons back. This also closes TotalFinder, which is an addon I use. So, I want to write an AppleScript which will run on startup, and do those two things: run the Terminal command, and then open TotalFinder.
I've written:
tell application "Terminal"
    activate
    do script "killall Finder" in front window
    quit
end tell
tell application "TotalFinder"
    activate
end tell
This gives me an error stating "Connection is invalid." when running the activate line for TotalFinder. The Terminal command is executed correctly. Any idea why this is? The application is definitely named correctly, its just in my root Applications directory so it should be able to find it, etc. How can I get this working?
Thanks!

try this:
do shell script "killall Finder"
tell application "TotalFinder"
          try
  activate
          end try
end tell
First thing you don't need to open a terminal window to do the killall you can just do to as a shell script.
Second don't know why TotalFinder gives that message about Connection invalid but it doesn;t seem to affect it any. So putting in the try just eats the error message.
Ypu may not even need the killall, When TotalFinder starts it restarts the Finder so you may be able to remove the killall
regards

Similar Messages

  • Applescript for running sudo commands in terminal

    I'm a newbie when it comes to Applescript and was wondering if someone could help with a basic request. I need to write a small script to do the following:
    1. Launch terminal
    2. Run the 'Sudo -s' command
    3. Enter the administrator password (in plain text)
    and then
    4. run some sudo commands like "sudo defaults write /Library/Preferences/com.apple.loginwindow HiddenUsersList -array-add administrator"
    I actually WANT the administrator password to be in the script in plain text even though I understand the security risks (I will literally be the only person to ever see the script). I've trawled forums all over but can't seem to find what I am looking for and cannot get it working by patching together the various commands I have found. Thanks in advance for any help you can give!
    Sean

    I've included two examples.  The preferred way & the hacker way.
    with administrator
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "sudo ls -l  " & quotedUnixDesktopPath with administrator privileges
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run
    This version has an inline password.
    Notice the echo 'password' |
    The single quotes are no accident.
    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
        Author: rccharles
        For testing, run in the Script Editor.
          1) Click on the Event Log tab to see the output from the log statement
          2) Click on Run
        For running shell commands see:
        http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
    on run
        -- Write a message into the event log.
        log "  --- Starting on " & ((current date) as string) & " --- "
        --  debug lines
        set unixDesktopPath to POSIX path of "/System/Library/User Template/"
        log "unixDesktopPath = " & unixDesktopPath
        set quotedUnixDesktopPath to quoted form of unixDesktopPath
        log "quoted form is " & quotedUnixDesktopPath
        try
            set fromUnix to do shell script "echo 'password' | sudo ls -l  " & quotedUnixDesktopPath
            display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
        on error errMsg
            log "ls -l error..." & errMsg
        end try
    end run

  • Terminal runs a command when opened

    Whenever I open the terminal, it runs some command I ran ages ago, for no appearant reason (in this case, CDs to some random library folder). It's getting quite annoying really, any idea what's causing this? If I knew what was causing it, I could set it to good use because there is a certain folder I DO need to cd into every time I launch the terminal...

    And the last command there is checked, but unchecking it didn't fix it either,Well, since there was no file (saved .term) specified it shouldn't make a difference.
    The simplest thing to do is to clear Terminal's preferences, by dragging ~/Library/Preferences/com.apple.Terminal.plist to your Desktop (with Terminal not running) and try again. If that clears it you can Trash the .plist from your Desktop.

  • Creating/running Terminal command with Automator

    I am using Parallels Desktop on my iMac. Occasionally after I shutdown Parallels Desktop/Windows the ram it used is not released back, for example, depending on what I'm running in Parallels Desktop I can use upto around 16GB or ram. Ocassionally when I shutdown Windows and in doing that Parallels Desktop too, this ram level does not go back down. I find that going into Terminal and entering the purge command puts the ram level down to what it was before I loaded up Parallels Desktop.
    I was wondering if its possible to use Automator to create a shortcut that I could then either place on my Desktop or Dock and when needed I could just double click on it and it would then load Terminal and then the purge command?
    Or is there another way that I could automate the purge command?

    I managed to work it out for myself.
    I done the following:
    In Automator I chose Application/Run Shell Script. In the box that appeared in the right side I entered purge. I then saved it to my desired location and I then dragged it onto the Dock for easy access.

  • How to run Terminal commands in Xcode?

    Anyone knows how to include Terminal commands ( like sudo) in Xcode?  for example in a line of my program I need to run this:
    sudo open/Library/Preferences/com.apple.sharing.firewall.plist
    I searched the library but found no class or routine for that.

    Well, I am not a professional programmer, but one of the things I continue to learn is how to wade through all of the Cocoa documentation (and it does get deep in spots).  Chances are though, no matter what you are trying to do, Apple or some third party has created a class to make it easier - you just have to find it.  My Xcode documentation bookmarks continue to grow, but you might start with some of Apple's documentation, such as
    Cocoa Fundamentals Guide
    Foundation Framework Reference
    Application Kit Framework Reference

  • Applescript to run ant command

    Hi,
    I need an applescript to run an ant command "ant init clean compile run".
    Please help.
    Thanks.

    Here is a very abbreviated AppleScript. It launches a terminal window and runs ant in it. Using the AppleScript editor in /Applications/Utilities, you can compile this and save as an application. I called mine antics. This will leave a spare Terminal window laying about, which you may find useful to review any ant output. If no Java is installed, the ant activity will trigger a system dialog requesting Java installation.
    --AppleScript
    tell application "Terminal"
      activate
              do script "/usr/bin/ant init clean compile run"
    end tell

  • Run menu command to open ipv4 properties on NIC directly

    hi friends
    in windows 2008, to set ip address in GUI, we need to run ncpa.cpl, select NIC, properties, select ipv4 , select settings. as we see this is a long process.
    is there any trick so that we right something in run menu & system directly open ipv4 properties which provides us ip address page?
    for example somthing like this----> ncpa.cpl:NIC:ipv4
    thanks in advance

    Those are not scripts they are command lines.
    As an administrator with 10 years of experience you should know that there is no simple way to do what you ask.  You can write a script to allow a user to view the network properties of any adapter or configuration but you cannot have NCPA open to a
    specific adapter's property page. No one is wasting your time.  You are asking a question that cannot be answered.  What you want to do cannot be done.
    You should also spend a bit of time looking into what scripting is.  It is not how to type a command in the "Run" menu box.
    I have over 30 years experience.  I have heard this same question from new users many tmes as have most of use here.  It is hard to think that an trained and certified Windows Nertwork and system sadminitrator could make this mistake.
    Try searching the web and you will see how many times this question has been asked by new users with not results.
    I recommend starting here as you will begin to understand why this is as you learn how to write an administrative script.
    http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx
    And don't get mad.  Even people who have managed their own office computers can be successful without training.  Windows is designed for simplicity until you have to do something technical then it is as bad as trying to fix your own plumbing. 
    Either get a do it yourself plumbing book or hire a plumber.  You cannot guess at how to replace a soil line or how to repair a furnace.
    ¯\_(ツ)_/¯

  • Running Terminal Commands at Login

    Hi everyone!
    Just a quick question for anyone who may know the answer. I am trying to automatically run two terminal commands at login:
    sudo pmset -a halfdim 0
    sudo pmset -a halfdim 1
    I have absolutely no idea what I am doing, so if someone knows and can help me out, that would be great! Thanks a lot!
    ~ Philip

    Trying to make the screen wink at you when you login?
    You could install Platypus and create a little shell script with it and put it in your Login items. The script would be something like
    <pre class=command>sleep 30; sudo pmset -a halfdim 0; sleep 0.2; sudo pmset -a halfdim 1</pre>
    Those sleeps should be tweaked for the best effect. If sudo prompts you for a password, then it won't work.
    Message was edited by: jarik
    Hey man, check out the day we registered here!

  • What is the terminal command to open sound preferences in Mac Snow Leopard

    Hi
    I want to know what is the command to open sound preferences dialog from command prompt.
    short key for doing this is option key + F12. But I am looking for somehting I can enter in terminal to open sound preferences.

    Get under the hood with Command Line and the Terminal. Unix forum is here for fast answer:
    http://discussions.apple.com/forum.jspa?forumID=735

  • Running Unix Command from WEB-APPLICATION

    Hi all,
    I want to run unix command from a java-based web application. the basic code part is this ---
    public class RunCommand
          public String runIt()
              String s = null, returnString = "";
              Process p=null;
              try
                       Runtime rt = Runtime.getRuntime();
                  p = rt.exec("sh testPOC.ksh");
                  p.waitFor();
                  BufferedReader stdInput = new BufferedReader(new
                       InputStreamReader(p.getInputStream()));
                  BufferedReader stdError = new BufferedReader(new
                       InputStreamReader(p.getErrorStream()));
                  // read the output from the command
                  returnString += "Here is the standard output of the command:<br>";
                  while ((s = stdInput.readLine()) != null) {
                      returnString += s;
                  // read any errors from the attempted command
                  returnString += "Here is the standard error of the command (if any): <br>";
                  while ((s = stdError.readLine()) != null) {
                      returnString += s;
              catch (IOException e)
                  returnString += "exception happened - here's what I know: ";
                  returnString += "error-> " + e.getMessage();
              catch(Exception e)
                returnString += "exception happened - here's what I know: ";
                  returnString += "error-> " + e.getMessage();
              return returnString;
      }this class is kept as an inner class. The control comes to its outer class, from servlet, from which the runit() is called. but the exception is occuring at line of p=rt.exec(.....). it tells "<command name> : not found transaction completed" [got this using getMessage() method].
    i am unable to show(and see, too) the stacktrace, because i don't have access to that test environment and its log. i can't run this in local because its windows one.
    now can anyone tell me, where is the problem. is there any limitation in web application server/container? this was successful when i used command prompt writing a .java file. Please help me. Thanks in advance...

    Friends, i've got, where the problem is.
    when we run a class file directly from a command prompt, we get an environment with that shell window. but for a servlet application running these kind of commands from a class creates kind of child processes. each and every command is executed as a child process of jvm and don't get those environment. we have 'PATH' variable in the environment. when a command (say, 'dir' or 'sh' or 'ls', etc.) is executed, the shell first search for that executable file (i.e. dir / sh / ls) in the given paths in the variable 'PATH'. this is not available for the child commands of jvm. hence the basic commands are searched in the current directory of the jvm and they are failed.
    i solved the problem giving full path of the commands. like :
    p = rt.exec("/bin/sh runningScript.ksh")

  • UNIX command to open applications

    I'm looking for a UNIX command to open any application on a client machine.
    I am also looking for a command to set the time of each machine to use a Network Time Server.
    Any help would be appreciated. Thank you.

    open /Applications/path...
    e.g.
    open /Applications/Safari.app
    time server:
    # turn on network time and designate a network time server.
    systemsetup -setusingnetworktime on;
    systemsetup -setnetworktimeserver time.apple.com;
    the time unix commands are available as a template from the send unix command window.

  • Quicker way of running terminal commands?

    Hi,
    I have a .sh file that I need to execute regularly. Up until now I have been opening up terminal and running code similar to this:
    cd /
    cd Applications
    cd SimpleDesktop
    bash sdesktop.sh
    Wherupon the file would execute and JRE would take over. I have tried just bash then dragging the file into the terminal but that doesn't work; I have to change directories manually first for some reason.
    What I would love to know if, through the wonders of OS X, there is a way of eliminating all that typing. If I could just click an icon and sdesktop.sh would launch it would be great.
    The .sh file is desperate to open in TextEdit by default.
    Help is much appreciated
    Message was edited by: Rory Mercer

    Everybody is going to scream.
    I opened Automator. I selected Automator from the list of apps. This narrows it down to where you can see "run shell script". Drag that into the window on the right. I then pasted in the single line of text I had copied from a website that was discussing unmounting volumes. I think I left the pass setting as "to stdin". If you select the option to show action when run it will prompt you each time you run it. Now save as an application. Double click to run the app. In my case the app takes several seconds to run despite it being only one line, but maybe that's because the drive has to be put away before I see anything.
    Okay, I have never done any thing at all with Automator before this, don't know anything about shell scripts, just know a few Unix shell commands. If you do anything with this that goes wrong I don't know you, have never heard of you, and I'll claim somebody hacked my computer and pretended to be me writing all this. On the other hand if it works I will bask in the glory of the multitude of blessings from you.
    Seriously, back up your drive before you do this. I really am a novice and I know just enough to be dangerous.

  • Using automator/applescript to do terminal commands/ssh

    hi,
    pardon my extreme novice question here, but i was looking for quick & easy ways to create a small applet to basically run a script on a web server to remotely check & update it's IP address with its web host, and also serve internet services to a wifi access point.
    here's the basic stuff we usually do in terminal —
    my-Computer:~ admin-user$ ssh admin@+{web server IP, ex.: 0.0.0.0}+
    +{we then have to wait for it to connect and ask for a password}+
    Password: {our input for password}
    Last login: Sat Jun 14 15:04:58 2008 from 0.0.0.10
    Welcome to Darwin! +{so we are now connected}+
    www:~ webserver-admin$ sudo /var/root/IP_update.sh
    +{there is then a long output as that script runs and updates the IP with the web host}+
    www:~ webserver-admin$ sudo route add -net 0.0.0.0/24 0.0.0.3 +{serve up internet services to a wifi access point, returns output that it was done, failed or already connected}+
    www:~ webserver-admin$ sudo /opt/local/sbin/lighttpd -f /opt/local/etc/lighttpd/lighttpd.conf & +{starts up our web server, returns that it was started or already on because port 80 is in use}+
    so that's what i want it to do. i thought using automator and the *run shell script* option in it would work, but i can't even get past the first ssh command without an error. i have it set to use /bin/sh, and have tried it with *pass input* setting set either way, *to stdin* or as arguments, but in either case, just on this first line alone, i get the following error —
    Run shell script failed
    Pseudo-terminal will not be allocated because stdin in not a terminal.
    does anyone know why this is happening? how do i get around this and proceed on with my script using automator?
    also, if anyone could please give tips about how to use the "pause" to have it wait for prompts over the network (like the "Password:" prompt coming back after an indeterminate number of seconds) and which automator command might be used to pop up a dialogue for user input (like asking for the password), it would be much appreciated. thanx.

    You'd want the *do shell script* command in AppleScript for this
    http://developer.apple.com/technotes/tn2002/tn2065.html
    however you're not going to be able to use it as you would tools such as Expect which allow you to wait and provide additional input on stdin. If all you're doing is updating an IP address why not simplify the entire mess with BIND's dynamic updates?

  • Run a report without opening application

    I need a report to be run daily but i do not want the Crystal Report XI to open to allow any editing to the report. I understand that CR viewer can open saved reports but i need the report to be refreshed daily.

    Not sure how you can setup non editing option in the report however, I have read this article right from the help file of Crystal Reports which might help you.
    Refresh Report Data command
    Use the Refresh Report Data command to retrieve fresh data for your report when you display it in the Preview Tab.
    When you refresh a report that doesn't have saved data, Crystal Reports retrieves data from the database; otherwise, the program discards the report's saved data and retrieves new data.
    Note: Refreshing a report's data does not necessarily refresh a subreport's data at the same time. Crystal Reports generates subreport data only when the subreport is encountered. For example, if a subreport is located on the second page of your report, the data for that subreport is not retrieved until you view the second page.
    By design, Crystal Reports only retrieves data when necessary. When you preview your report in the Preview tab, print the report, or export it to a file, the program runs your report and retrieves the required data. Once you are working with the data in the Preview tab, the program will run the report again and retrieve fresh data if you:
    Add fields to the report after the report was run.
    Add a formula that references a field that was not in the report when you ran it the first time.
    Expand your record selection criteria to include more records than were needed when you first ran the report.
    Aside from these circumstances, the program will not automatically refresh a report.
    However, there may be times when you want to retrieve new data for the report. For example, you may have created a report several days earlier and you want to see it run with the most current data.
    The Refresh Report Data command is intended for times such as this.
    Regards
    Jehanzeb

  • Terminal command for opening Safari fullscreen by default?

    Not fullscreen per day, but maxed out so I can still see the menu bar. Or at least to open with a bit more padding? Safari generally does a good job, but every now and then I'd like my window a bit larger.

    Champ, it doesn't seem like you are trying to be very helpful at all, maybe stay out of this discussion. I'm after a solution to a very specific problem which I'm quite certain is some sort of bug.  Many other users have reported the same issue..
    http://forums.macrumors.com/showthread.php?t=1205106
    http://forums.macrumors.com/showthread.php?t=1230067
    http://forums.macrumors.com/showthread.php?t=1226754
    https://discussions.apple.com/thread/3762299?start=0&tstart=0

Maybe you are looking for

  • Oracle Forms New Features - Your input.  Supporting data types

    I am interested to know IF we were to support any new database types in Oracle Forms 11g, which types would you like supported and why. I'd also like to know if you are currently working around the absence of a database type. Please note, this is not

  • Error in HRPAD31 ( Short dump Analysis )

    Hi friends, When i am changing the existing qualification or adding new qualification it is showing this error in short dump Pls advise me if there is some relationship i am missing in 031 ? here is the description of short dump Runtime Error  DBIF_R

  • Performance View with data from Custom Rule

    Hello again everybody, so we created a vbscript which measures time needed for a specific process inside a program. Now we made a rule for getting this data inside SCOM. Alerting and Health-Monitoring works fine. For example, we made "if TimeNeeded>5

  • Process chain: rspc

    In checking view of PC i get : A type "Attribute Change Run" process has to follow process "Save Hierarchy" color : yellow However, in log view everything is in Green (meaning Ok) Why the differ in the above two / what does it mean ?

  • Sticky Threads

    Okay, I admit, this is just a pet peeve of mine, but it seems that about half the sticky threads at the top of this forum are either outdated or badly outdated. Two examples; Can I REALLY still win a CS3 Master Collection? And how many people are sti