Apple Script Help, "do shell command"

Discussion in 'Mac Programming' started by Ohsnaptakethat, Mar 18, 2008.

  1. macrumors newbie

    Mar 18, 2008
    Hey all,

    After moving to Leopard I have noticed that the Finder, and more importantly Spotlight have completely lost their usefulness to me. As a new sys admin I loved being able to type in some obscure plist I needed to edit into Spotlight and have show right up. But that was in Tiger and this is Leopard, now when I type in anything I get Safari History items, and really random txt files that I really had no idea existed.

    So instead I have been using terminal to do my dirty work. Using the
    "find / | grep -i variable" command.

    I would like to build a little Applescript that ran that command, but with the variable be something I type into a dialog box. And then just have it spit the results out.

    I know this might end up requiring more then just Applescript, possible Xcode, but who knows.

  2. macrumors regular

    Mar 6, 2007
    I am not in front of my mac, but IIRC you could try something like this:
    property theCommand : ""
    repeat while theCommand is ""
       display dialog "Enter the value to search for:" default answer theCommand
       set theCommand to text returned of result
    end repeat
       do shell script "find / | grep -i  " & quoted form of theCommand
    on error errorMsg number errorNum
       display alert "Error " & errorNum message errorMsg buttons "Cancel" default button 1
    end try
    Also check out Automator. There is a lot of cool stuff you can do, including having it prompt you for variables to insert into the commands to follow.

Share This Page