Previous 1 2 Next 24 Replies Latest reply: Apr 30, 2014 5:39 AM by pitouilles
Larry McJunkin Level 1 (30 points)

I've looked at the possible answers that come up when I ask this question here, but none really fit my question.

 

I want to automate the Terminal command that cleans out obsolete entries in my right-click "Open with" menu, which I have to do often. Rather than copying the command each time I want it, then opening Terminal, pasting it in, etc., is there a way to automate this with Applescript?  Thanks!


iMac, OS X Mavericks (10.9)
  • Niel Level 10 (298,586 points)

    Use code such as:

     

    do shell script "ls -l ~"

     

    (99949)

  • Larry McJunkin Level 1 (30 points)

    Thanks for the fast reply, Niel. I understand this is a newbie Applescript question, but over the years I have just never used Applescript and other than this one thing, probably won't again.  So rather than take hours to learn it, I hope you don't mind the additional question regarding this.  Do I just put the following into the main Applescript editor?

     

    do shell script "ls -l ~"

     

    /System/Library/Frameworks/CoreServices.framework//Versions/A/\

    Frameworks/LaunchServices.framework/Versions/A/Support/lsregister \

    -kill -r -domain local -domain user;

    killall Finder

  • Niel Level 10 (298,586 points)

    Use the following:

     

    do shell script "/System/Library/Frameworks/CoreServices.framework//Versions/A/\

    Frameworks/LaunchServices.framework/Versions/A/Support/lsregister \

    -kill -r -domain local -domain user"

    tell application "Finder" to quit

     

    (99951)

  • Larry McJunkin Level 1 (30 points)

    I got the following error:

     

    sh: /System/Library/Frameworks/CoreServices.framework//Versions/A/: is a directory

    sh: line 1: Frameworks/LaunchServices.framework/Versions/A/Support/lsregister: No such file or directory

    sh: line 2: -kill: command not found

  • Niel Level 10 (298,586 points)

    Here:

     

    do shell script "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Launch Services.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user"

    tell application "Finder" to quit

     

    (99954)

  • Larry McJunkin Level 1 (30 points)

    Copied exactly...here's the error (it's getting shorter, anyway).

     

    sh: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Launch: No such file or directory

  • Larry McJunkin Level 1 (30 points)

    BTW, the command itself in Terminal does work OK.

  • Niel Level 10 (298,586 points)

    Delete the carriage return after Launch; the entire do shell script command needs to be on a single line.

     

    (99960)

  • Larry McJunkin Level 1 (30 points)

    Well, that was scary!  I ran the Applescript and it didn't give me any errors, but my desktop went completely blank...no icons at all...for over two full minutes!  It finally came back, but I think I'll forget about automating it. When I run this command in Terminal, it simply blinks the desktop icons off and then right back on again as it kills Finder and rebuilds the desktop.

  • Niel Level 10 (298,586 points)

    Add the following to the end of the script:

     

    tell application "Finder" to run

     

    The difference is that the Finder automatically relaunches if forced to close. Being told to quit by an AppleScript command is easier on it but doesn't count as a forced closure.

     

    (99965)

  • Larry McJunkin Level 1 (30 points)

    That is already at the end of what you told me earlier (12:09pm).

  • Larry McJunkin Level 1 (30 points)

    Ooops...read that wrong.  That was the kill command.

  • Niel Level 10 (298,586 points)

    No, it isn't; the line I gave you in that post has quit at its end, and this one has run.

     

    (99967)

  • Larry McJunkin Level 1 (30 points)

    OK, just to make sure, this is what I'll try "after" you say it's OK.

     

    do shell script "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Launch Services.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user" tell application "Finder" to run

Previous 1 2 Next