Using Applescript to execute a Terminal command

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!

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

Similar Messages

  • Using Ant to execute WLST setAppMetadataRepository command

    I am having a problem using Ant to execute the setAppMetadataRepository WLST command. This command puts an entry in adf-config.xml that points to the MDS datasource.
    This is the ant task that I'm using. These commands work from the WLST tool, but when using them with Ant, I get the error below.
       <target name="setAppMetadataRepositoryUsingWlst">
          <wlst debug="true" failonerror="true">
             <script>
                archive = getMDSArchiveConfig(fromLocation='C:/ADE/michande_platSavedSearch/commsplatform/ri/dist/comms-ri.ear')
                archive.setAppMetadataRepository(repository='mds-commsRepository',partition='riPartition', type='DB', jndi='jdbc/mds/commsRepository')
                archive.save()
            </script>
          </wlst>
       </target>Here is the error that I get (NameError: getMDSArchiveConfig). This is saying that getMDSArchiveConfig isn't a recognized command. Other commands (like connect(...)) work ok from ant, but not these MDS commands. Is this a bug or am I doing something wrong here?
    [wlst] <WLSTTask> All lines will be trimmed by 12
    [wlst] <WLSTTask> Line: archive = getMDSArchiveConfig(fromLocation='C:/ADE/michande_platSavedSearch/commsplatform/ri/dist/comms-ri.ear'). Final trim length: 12, String length: 124
    [wlst] <WLSTTask> Line: archive.setAppMetadataRepository(repository='mds-commsRepository',partition='riPartition', type='DB', jndi='jdbc/mds/commsRepository') . Final trim length: 12,
    String length: 147
    [wlst] <WLSTTask> Line: archive.save(). Final trim length: 12, String length: 26
    [wlst] <WLSTTask> The script that will be executed
    [wlst] archive = getMDSArchiveConfig(fromLocation='C:/ADE/michande_platSavedSearch/commsplatform/ri/dist/comms-ri.ear')
    [wlst] archive.setAppMetadataRepository(repository='mds-commsRepository',partition='riPartition', type='DB', jndi='jdbc/mds/commsRepository')
    [wlst] archive.save()
    [wlst]
    [wlst] Error: Error executing the script snippet
    [wlst] archive = getMDSArchiveConfig(fromLocation='C:/ADE/michande_platSavedSearch/commsplatform/ri/dist/comms-ri.ear')
    [wlst] archive.setAppMetadataRepository(repository='mds-commsRepository',partition='riPartition', type='DB', jndi='jdbc/mds/commsRepository')
    [wlst] archive.save()
    [wlst]
    [wlst] due to:
    [wlst] Traceback (innermost last):
    [wlst] File "<string>", line 1, in ?
    {color:red} [wlst] NameError: getMDSArchiveConfig{color}
    Thanks,
    Mike

    Not all WLST installations are equivalent. Have a read of [http://www.oracle.com/technetwork/articles/adf/part10-085778.html]this, specifically the paragraph right after Figure 13 for something to try. Bottom line - the WLST that comes with the base WLS server install cannot do the MDS operations.
    John

  • How to execute a Terminal command on startup?

    Greetings!
    Is it possible to automatically run a Terminal command at startup? (Specifically - a hwprefs command.)
    If so, could you please detail the steps involved?
    Many thanks!

    OK, then, that's pretty straight forward. You can write a small AppleScript like so:
    set mystring to do shell script "Insert Command String Here" with administrator privileges
    If you need to run the command with root permission then insert "sudo" before the command line, i.e., "sudo commandline". You will need to authenticate in this case so add "with adminstrator privileges" after the command string, i.e.,
    do shell script "sudo command string" with administrator privileges
    Compile the script as a run-only application then add the compiled script to your Login Items (Accounts preference pane.)
    Note that your command line will need the fully qualified path to the command.

  • Using WLST to execute SOA Suite commands

    Hi,
    using SOA Suite 11g R1 PS1 (11.1.1.2.0)
    I am trying out the WLST commands as described in the documentation (http://download.oracle.com/docs/cd/E15523_01/web.1111/e13813/custom_soa.htm#CIHGBHAC), such as sca_listDeployedComposites and sca_undeployComposite. However, each command seems to fail with a NameError. Other commands (non-SOA Suite related) seem to work okay.
    Did anyone succeed in using the SOA Suite related command in WLST - the ones prefixed with sca_? If so: did you have to do any special set up or configuration to make it work? What is the exact syntax you are using?
    Thanks for any pointers.
    Lucas

    OKAY, it is resolved:
    To use those custom commands, you must invoke the WLST script from the Oracle home in which the component has been installed. Do not use the WLST script in the WebLogic Server home.
    The script is located at:
    +(UNIX) ORACLE_HOME_for_component/common/bin/wlst.sh+
    +(Windows) ORACLE_HOME_for_component\common\bin\wlst.cmd+
    I had started the wrong 'version' of WLST, the generic one and not the one in the SOA1 subdirectory that knows about the SOA Suite specific operations.
    regards,
    Lucas

  • Using SXPG_CALL_SYSTEM  to execute Unix 'MV' command not working

    Here is the code (method - params begin with "p_").  This returns no error but yet the file is not moved (called in a test program).  Any ideas?
    DATA: lv_sourcepath TYPE rlgrap-filename,
            lv_targetpath TYPE string,
            lv_fname      TYPE rlgrap-filename,
            lv_path       TYPE rlgrap-filename,
            lv_paramstr   TYPE sxpgcolist-parameters,
            lv_status     TYPE extcmdexex-status,
            lv_execproto  TYPE TABLE OF btcxpm.
      " Get physical path to archive folder
      lv_targetpath = zcacl001_utilities=>get_appserver_path( 'ZDIR_KHRIS_INTF_ARCV' ).
      " Type casting needed for function module call below
      lv_sourcepath = p_sourcepath_in.
      " Split filename from path in source
      zcacl001_utilities=>parse_file_path( EXPORTING
                                              p_fullname_in   = lv_sourcepath
                                           IMPORTING
                                              p_filename_out  = lv_fname
                                              p_path_out      = lv_path ).
      " Concatenate filename to target path
      CONCATENATE lv_targetpath lv_fname INTO lv_targetpath.
      " Build parameter string
      CONCATENATE '-f' lv_sourcepath lv_targetpath INTO lv_paramstr SEPARATED BY space.
      CALL FUNCTION 'SXPG_CALL_SYSTEM'
        EXPORTING
          commandname                = 'mv'
          additional_parameters      = lv_paramstr
          trace                      = space
        IMPORTING
          status                     = lv_status
          exitcode                   = p_exitcode_out
        TABLES
          exec_protocol              = lv_execproto
        EXCEPTIONS
          no_permission              = 1
          command_not_found          = 2
          parameters_too_long            = 3
          security_risk                  = 4
          wrong_check_call_interface = 5
          program_start_error            = 6
          program_termination_error      = 7
          parameter_expected         = 8
          too_many_parameters            = 9
          illegal_command                = 10.

    Try to put this type of entry in the Object request.
    Prog Obje Objectname
    R3TR EXCC commandname
    I am not sure, weather this will work or not.
    Regards,
    Naimesh Patel

  • Executing terminal command at startup

    What is the easiest way to execute a terminal command when OSX starts up?

    OS X has used Launchd to run startup items since Tiger (10.4). Create a .plist for the program
    you want to run and putting it in the /Library/launchAgents or the $HOME/Library/LaunchAgents
    directory, if you only want it to run at user login. Optionally, for user startup items, you can add
    the command to the Account login items, but it has to be in the form of a standalone unix script
    or automator app to work correctly as an Account login item.
    Here are some background resources on launchd:
    http://www.macgeekery.com/tips/allabout_launchd_items_and_how_to_make_oneyourself
    http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemS tartup/Articles/LaunchOnDemandDaemons.html
    http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/m an5/launchd.plist.5.html
    Here is a Gui app that can help you create launchd items:
    http://sourceforge.net/projects/lingon/files/
    Here is a thread on using Account login items to launch scripts and automator apps:
    http://discussions.apple.com/message.jspa?messageID=11569184#11569184
    Now, go start something.

  • Using applescript to open a folder with a keyboard shortcut

    hello -
    i have a rather simple question (probably). is there a way using applescript to create a keyboard command to open a folder? i.e. command shift a opens the applications folder and command shift u opens utilities. can i use applescript to designate a keyboard command to open a folder i have created? also, the script editor does not have to be open for me to utilize scripts, correct?
    thanks for your patience with a newbie.

    You can't make a keyboard shortcut to run a specific application from OSX, although there are third party applications such as Quicksilver that can do things like that. You can use an AppleScript to activate an existing menu item, for example:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Finder" to activate
    tell application "System Events" to tell application process "Finder"
    keystroke "A" using {shift down, command down}
    end tell</pre>
    Other alternatives to keyboard shortcuts are to use the Scripts Menu or add an application to the Finder's toolbar. The Script Editor does not need to be active to use scripts.

  • 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

  • Command executing on Terminal startup

    whenever i open Terminal, something is causing it to run a command:
    /Applications/GravSim; exit
    which invariably runs the command and exits, making the only way for me to actually get into a shell to be using the "New Command" option under "File". I've seen other posts with similar problems, but theres seemed to be fixable by editing a .cshrc or .login file, neither of which I can find using "ls -a" in any directories I would think would be normal (although I am somewhat new to terminal). The only thing I can figure is happening is that Terminal is for some reason running the last successful opening of Terminal (the last thing that may have opened terminal before this may have been me double-click-opening the shell program /Applications/Gravsim.
    is there some file im missing or something i can edit that will just make terminal always open regularly? (and yes, i have tried editing my preferences to execute a specific command (/bin/zsh) upon opening a new terminal window)

    Jason Merritt1 wrote:
    okay... i don't seem to have that file... or at least not in /Library/Preferences, now what?
    Try ~/Library/Preferences
    You must have it in there

  • Linux Commands Executable in Terminal?

    Hello Unix & Terminal users,
    I'm wondering if the following Linux commands can be executed in Terminal on OS X?
    fdisk /dev/sde
    d # delete the existing partition
    u # switch units to: sectors
    n # new partition
    p # primary
    1 # first partition
    XXX # first sector = XXX
    <enter> # press enter to select last sector automatically
    t # change partition type
    c # change it to FAT32
    a # make it bootable (required for later firmware)
    1 # first partition
    w # write table and quit
    After changing the partition table, reformat the memory card with
    mkfs.vfat /dev/sde1
    The commands are intended to be used on a memory card.
    Thanks in advance,
    Maximilian

    looks like you should be able partiton with [fdisk(8)|http://developer.apple.com/documentation/Darwin/Reference/ManPages/ma n8/fdisk.8.html], at least the binary is present.
    Other partitioning tools that are available are: [gpt(8)|http://developer.apple.com/documentation/Darwin/Reference/ManPages/man8 /gpt.8.html] and [pdisk(8)|http://developer.apple.com/documentation/Darwin/Reference/ManPages/ma n8/pdisk.8.html]
    as for creating a fat type filesystem. [newfsmsdos(8)|http://developer.apple.com/documentation/Darwin/Reference/ManPages/man8 /newfsmsdos.8.html]

  • Applescript Terminal Command Problem

    Hilo
    I am making an application that Alphabetizes words.
    Everything works except that whenever I get to this part -
    do shell script "cd ~/Public/Alphabetizer; ls -l *.pl; chmod +x Alphabetizer.pl; ./Alphabetizer.pl"
    does anyone know why nothing happens, and if you do,
    can you tell what to type to show what happens on terminal using applescript?
    ^_^ greatly appreciated

    What do you expect to happen? That command does not involve Terminal at all. If you want to check the stdout from the shell commands, you could use the Results pane and/or the Event Log in Script Editor. Or redirect the output to a file.
    If you want an actual Terminal window, you need to send the commands to Terminal, rather than directly to a shell. E.g.,
    tell application "Terminal"
    activate
    do script "ls -l"
    end tell
    Note that that is the Terminal's +do script+ command, not AppleScript's +do shell script+ command.

  • I get "App Store Disabled" on my MacBook Pro due to profile issues. What Terminal command can I use to reset profile settings?

    After transferring documents from one MacBook Pro to another I get some weird errors due to settings that seem to have transferred over. One is that the Mac App Store is disabled.
    Are there any Unix / Terminal commands I can use to reset these?

    Forgot Your Account Password
    For Lion/Mountain Lion
        Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
         When the menubar appears select Terminal from the Utilities menu.
         Enter resetpassword at the prompt and press RETURN. Follow
         instructions in the dialog window that will appear.
         Or see Reset a Mac OS X 10.7 Lion Password and
         OS X Lion- Apple ID can be used to reset your user account password.

  • How can I change the "Ask to join new networks" option using a terminal command?

    We are currently switching to a new wireless network throughout our school district and I have pushed commands to connect to the new and remove the old. However, any Macs that have "Ask to join new networks" enabled are jumping over to our unsecure guest network, even if that network has been removed from the list of Preferred Networks. So far the fix has been to remove the guest network from the list of Preferred Networks and then disable Ask to join. The only issue I'm running into now is I have been unable to find a terminal command to change this setting. Once I have the command I can write a script and send that out to all of the Macs.
    So is there a way to disable "Ask to join new networks" using command line?

    sed -i "" 's/Prompt/DoNothing/' /Library/Preferences/SystemConfiguration/preferences.plist

  • We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a

    We are trying to implement a process so that any document that needs to be printed through our Java application will be printed as PDF using Adobe Reader. For which, We created and execute the below command line to call Adobe Reader and print the PDF on a printer."C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" /T "\\<Application Server>\Report\<TEST.PDF>" "<Printer Name>". Current Situation: The above command line parameter when executed is working as expected in a User's Workspace. When executed in a command line on the Application Server is working as expected. But, the same is not working while executing it from Deployed environment.Software being used: 1. Adobe 11.0 enterprise version. 2. Webshpere Application Server 8.5.5.2. Please let us know if there is a way to enable trace logs in Adobe Reader to further diagnose this issue.

    This is the Acrobat.com forum.  Your question will have a much better chance being addressed in the Acrobat SDK forum.

  • Using cfexecute to execute dos command in windows.

    Hi!
    Well i have a requirement where i need to check status of
    particular service in windows from time to time.
    I inferred that we can use cfexecute for this. Well i tried
    to use the same but i was not successful in achieving the desired
    result.
    The following is the code i have written for the above
    purpose.
    <cfexecute name="sc query Internet Information Services"
    arguments="y"
    outputfile="d:\Temp\Output.txt"
    timeout="90" />
    I get the following message:
    oldfusion.tagext.lang.ExecuteTag$TimeoutException: Timeout
    period expired without completion of sc query Internet Information
    Services
    at
    coldfusion.tagext.lang.ExecuteTag.doStartTag(ExecuteTag.java:170)
    at
    cfserverchecking2ecfm748178803.runPage(D:\Test\serverchecking.cfm:3)
    at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)
    at
    coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)
    well i have tried using different timeout periods but it dint
    work for me.i have gone crazy with it.
    Please advice on this.
    Many thanks.

    In addition to Mr Black's suggestions, take a look at these
    two entries about using cfexecute on Ben Forta's blog
    http://www.forta.com/blog/index.cfm/2006/7/31/Using-CFEXECUTE-To-Execute-Command-Line-Util ities
    http://www.forta.com/blog/index.cfm/2006/9/11/A-Couple-Of-CFEXECUTE-Gotchas

Maybe you are looking for

  • PCI-e driver required?

    I have a new MSI G31 mobo with an E7400 processor which I now have operational. After installing my first PCI-e card (a GeForce 8400 graphics adapter) the device was not recognized. Before returning this card I was wondering where the drivers for the

  • If You Can Solve This One, Then You Seriously Win

    Here's the deal. I have a 3G 15gig iPod that I refuse to let die. It has a new battery that I recently installed. It will not charge through firewire to the wall or to my macbook pro, nor will it charge through usb (which goes without saying on 3G's)

  • Sending/Receiving Picture Texts

    Can someone please help? When I receive a picture text it says "get media content now" but when I tap on that it just dings and displays the same message. Also, I can't send out picture texts. It just says, "unable to send". I had this fixed once but

  • Toshiba laptop charger

    Hey so I have a question. I have a Toshiba Satellite A205-S4587 laptop. My charger adapter recently broke so i need a new one. My current charger part number is PA3467U-1ACA. But when i looked it up, my only compatible charger part number is PA3290U-

  • What does a number in upper righthand corner of FaceTime icon mean?

    Since yesterday there is a number 1 in the upper right-hand corner of the FaceTime icon on my iPad (iOS 7.0.2 - doesn't seem to be available in "my products"). I suspect that this is related to an attempted FaceTime call which didn't get through to m