Applescript (Terminal)

I am a new Applescript user. I have a script that will run a Terminal command.
How can I get the script to run in the back ground and not open Terminal?

How can I get the script to run in the back ground and not open Terminal?
Simple - don't use Terminal.app. Have AppleScript run the shell command directly:
do shell script "/path/to/command -args -moreargs"
You only need to use Terminal.app if the command is interactive.
There are many issues with the above approach, though, including things like authentication and long-lived processes (AppleScript will wait for the shell command to finish before it continues). Search the boards or post back if you need help with those kinds of things.

Similar Messages

  • Applescript - Terminal opacity & blur settings

    Opacity and blur don't seem to be supported in AppleScript.
    Is there any workaround to set their values?
    Is there any way to dynamically apply a settings set with e.g. different background color?

    I, too, can't see an easy way to set the opacity - I vaguely recall doing it in the past but my memory fades.
    However it's easy to change the settings set of any given window:
    tell application "Terminal"
              set current settings of window 1 to settings set "Red Sands"
    end tell
    Change the name as appropriate, of course.

  • Applescript: terminal unrar command

    Hey,
    I would like to know if it's possible to make an applescript of the following terminal command(s).
    cd
    unrar e -r -o- *.rar && find ./ -name “*.r*” -delete
    Also, I would like to know if it's possible to tweak the "unrar e -r -o- *.rar" command.
    Following situation:
    Main_folder\SubfolderA
    Main_folder\SubfolderB
    Main_folder\SubfolderC
    when I login in to terminal and use the command => unrar e -r -o- *.rar
    Everything from SubfolderA / SubfolderB & SubfolderC will be extracted in Main_folder
    Now my question is: Is there a command that will extract the "*.rar" in the same subfolder as where they are stored.
    Kind regards,
    Maxime

    Hi Frank,
    I try to unrar .rar files.
    I've managed to tweak my automator script:
    on run {input, parameters}
      tell application "Terminal"
      activate
      do script with command "cd /Volumes/****_storage/Downloads && unrar e -r -o- *.rar && find /Volumes/****_storage/Downloads -name *.r* -type f -delete"
      end eend tell
    eenend run
    The the subfolder remains an issue.

  • Applescript, Terminal 2.0 and opacity

    Is there a way to change terminal opacity in an applescript on leopard ?
    it seems to be possible on previous version, but since "background color" now take a RGB color, it's not possible to put the alpha as 4rth argument.
    navigate in the "Preferences" menu with GUI scripting isn't an option

    Can you provide more detail?
    I'm trying to set the front window settings to one of the named profiles that I defined in Terminal preferences. I'm not sure how Applescript interprets "settings set".
    tell application "Terminal"
    do script "uptime"
    tell front window
    activate
    set current settings of front window to <one of my window settings>
    end tell
    end tell
    Actually, what I really want to do is launch one of my defined Window Groups with Applescript. Seems like it should be easy... but I have never found Applescript to make much sense.

  • Applescript/Terminal: Get PIDs of processes starting with...

    Hello,
    Is there a way to return all the PIDs of processes starting with "Myapp_action_download" in a neat array in Applescript, so I can kill them using Terminal?
    Something like this:
    set openapps to {}
    set openapps to (do shell script "the shell script which I don't know")
    --This script gets all the PIDs of processes starting with "Myapp_action_download", and returns them in a neat array
    set appcount to 0
    repeat (count of items of openapps)
    set appcount to appcount + 1
    do shell script ("kill -9 " & (item appcount of openapps) as text)
    end repeat
    Kind regards,
    Isaiah

    try
    tell application "System Events"
              set procesList to the name of every process whose name contains "Myapp_action_download"
    end tell
    tell application "System Events"
              set {procesList, pidList} to the {name, unix id} of (every process whose name contains "Myapp_action_download")
    end tell
    You'll have two lists one with the process name and one with the pid's. They will be in a one-to-one relationship. That is the first entry in the processList will correspond to the first entry in the pidList.
    However if the apps aren't hung or in a weird state you should be able to just tell the process to quit without resorting to killing them.
    Message was edited by: Frank Caggiano

  • 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.

  • Applescript/terminal to get website text

    Hi.  I'm trying to use applescript to define a word using Google. The best way I as able to do this is by using the command
    do shell script "curl https://www.google.com/#q=define:" & wordtosearch & ""\
    The only problem is that this command returns the whole webpage. I would like to get just the definition from the top result from google.  To see what I mean, type "define:hello" into the Safari or Chrome address bar, then the definition for hello will appear as the first result.  I'd really appiciate help on that.

    Do you actually need to get the deffinition from google? 
    You can use the Built in dictionaries by using the following:
    do shell script "open dict://" & wordtosearch
    You can use it with a dialog such as this:
    display dialog "Enter word to define:" default answer ""
    set wordtosearch to (text returned of result)
    do shell script "open dict://" & wordtosearch
    Hope that this helps you some.

  • Escape button doesn't work in iTunes, iWork, Preview switching back to non-full screen mode

    Though it does in Safari, iPhoto. Is it possible somehow by means of AppleScript, Terminal (or smth else) to enable esc button to switch between full and non-full mode assigning it to all of my apps or is it a bug?
    ILYA

    But I want use just one button instead of combination of them. Isn't it possible to make esc button the general screen mode switching tool?

  • Create an context menu item to open a file on a specific display

    Hello,
    I have an external display connected to my MBP, but I don't always need to use it so it's not always on. I'd like to have a way to open a file (or application) on a specified display on a case by case basis. I know that I can assign an application to open on a specific display by right-clicking on the app in the dock and selecting options->assign to. The problem with this is that it's a global change. When I'm working on school work, I usually like to have reference material (pdfs, wepages, etc) open on the external display while I'm working in Word on the MBPs monitor.
    What I'd like to be able to do is right click on the file (or app) and use a context menu item to open the item on a specific display. Does anyone know of an automator action/applescript/terminal command to create a context menu item like this?
    Thanks.

    I use "Open Terminal Here" script for that:
    http://www.entropy.ch/software/applescript/

  • How to enable Minimizing Window in all apps by pressing "escape" button?

    ...cause I found long ago that pressing esc does this just for Safari, Preview, iPhoto but it does NOT in iTunes, iWork. Is it possible by means of AppleScript, Terminal or smth else to assign this command to every app on my Mac and if yes, then, how exactly?
    Thanks in advance
    ILYA

    Hi,
    We have created FAQ for log collecting with new versíon 3.2:
    How can i send the log files with the Nokia Suite 3.2? 
    Disconnect your device from your computer and exit Nokia Suite from File > Exit. Enable log gathering by double-clicking the enable_logs.js file in installation folder, normally C:\Program Files\Nokia\Nokia Suite. Then open Nokia Suite again and reconnect your device. Try to reproduce the error and click Help > Send feedback in Nokia Suite menu and fill in the description of the bug. Log files and system information will be automatically included in the feedback. You can also add screen shots and other files by choosing Add file (maximum size 5 MB).
    Please let us know  for the result.
    Br
    Mahayv

  • Mov to animated gif

    hi, i'm really confused by this. i do not want to dish out 94€ for Camtasia for Mac, i'm really guessing there has got to be an automator/applescript/terminal/anything method of taking a screen-recorded .mov  and turning it into an animated gif. but how do i do it, please?

    The first question is why do you want GIF? The colors in your screen recording will look terrible when reduced using GIF.
    QuickTime X can create screen captures and it is a free part of Snow Leopard. The newer version in Lion and Mountain Lion can also capture an "area" of the screen as opposed to the entire display in the 10.0 version.
    QuickTime Player Pro can convert your screen recording into individual images and you could import them into a GIF editor (if you can find one that works). Search for Gif Fun. My old copy from 2008 still works.

  • How can a remotely launched Applecsript display dialog?

    I have many Mac-computers running a variety of Mac OS X systems, including Tiger, Leopard, and Snow Leopard. On Tiger and Leopard, a Terminal bash-script could launch a compiled and saved Applescript (in /Applications/myLogout.app), which uses "say" to tell the user the system is going down in two-minutes. It then waits (delay 120), and then uses "say" again with this message, "System going down in 10 seconds". That's followed by a "display dialog" with the same message. The User could "Cancel" to stop the execution of the Applescript. If not, the applicaton proceeds to do cleanup work, like eliminating pesky /var/tmp files that invariablely end up as "Recovered" files or folders, and then it does "shut down".
    I could remote login from another computer and execute this simple bash-script:
        #!/bin/bash
        if [ -x "/Applications/myLogout.app" ] ; then
           osascript /Applications/myLogout.app display >/dev/null 2>&1"
        else
           echo "Can't find Logout application"
        fi
        exit 0
    This bash-script would wait at the osascript command until the Applescript terminated, which it did either because someone clicked Cancel in the dialog, or the "shut down" command occurred. My session then regained control, and usually was quickly terminated as a remote session.
    But now, Snow Leopard wouldn't properly execute the Applescript. It always fails for lack of a WindowServer connection to my remote session.
    I can't use launchd for this because of similar restrictions. For one thing, I have no clue who might be the active user on the target computer, and never had to worry about that because the "display dialog" was always presented to the "current" user. So, basically, Apple has removed the capability that existed in both Tiger and Leopard. Furthermore, their "solution" of using launchd doesn't cover this scenerio: - - remote launch of a UI application that warns the "current user", does a lot of cleanup work, and shuts down the computer.
    I can do everything in a bash shell except present a dialog to give the "current user" a chance to Cancel. Basically, the myLogout application can be launched by the "current user", and since it doesn't have an input parameter, it doesn't wait or do the dialog. That works. But even when called from a bash-script WITHOUT a parameter (that's the "display" word in the sample), it still fails in Snow Leopard.
    One final note: The "Product" listed with this post is NOT my Snow Leopard system, but it's NOT 10.4.11 either. I'm on 10.5.8

    One of us is confused about something, and I'm not sure which of us it is.
    What message are you trying to pass? If you want a formulaic "Shutdown in two minutes" message then code it directly into the script and don't bother with passing it. If you want a custom message that might change on different runs, then the easiest solution is to call a handler of the application on the remote machine and pass the message as a parameter.  just for an example, do this:
    Put this script as a stay-open script application on the remote machine:
    global idleInterval, message
    on idle
              try
      -- error catching. when you call handler x(), first the script's run handler will run, then the idle handler, then x(), and the the idle handler in a loop. this prevents unset variable errors on the first pass.
      message
      idleInterval
              on error errstr
                        return 1
              end try
              if idleInterval is "Start" then
      say message
                        set idleInterval to 10
              else if idleInterval is 10 then
      say message
                        set idleInterval to 5
              else
                        display dialog "System wants to shut down"
                        set idleInterval to 1
                        quit
              end if
              return idleInterval
    end idle
    on x(textMessage)
              set idleInterval to "Start"
              set message to textMessage
    end x
    go back to the admin machine and run this command in the applescript editor:
    tell application "ShowMsg" of machine remoteMachine
              x("Whoohoo!")
    end tell
    If it asks for authorization, give it. You can either save it in your keychain or we can work through the auth problem next.

  • Is there a way to stop the launching applications to come to foreground?

    Is there a way to stop the launching applications to come to foreground?
    Back with os 10.3 Panther or 10.4 Tiger the apps opened in the background. That was one of the good differences with Windows. I guess that 10.5 Leopard adopted this annoying Windows behavior. Hope it's gonna change with 10.7 Lion.
    (Of course I am looking for another solution than the AppleScript/Terminal launch that can be found on Google. I'd rather have a plist option to change if it exists!)

    I have found this page http://www.realsoftware.com/listarchives/realbasic-nug/2009-03/msg01167.html where it is proposed to add :
    <key>LSBackgroundOnly</key>
    <string>True</string>
    to MyApp.app/Contents/Info.plist
    I tried this but the app launches totally hidden in the background. Plus you have to set this behavior for every app.
    The open -g option works fine as expected.
    Still looking for a system-wide option, but it doesn't seem to exist.
    About the utility of such an option, I'll just remember you that some machine don't load apps very fast and, instead of waiting for an app to launch, the user will do something else until the app launches. You'll understand that waiting in front of a computer isn't acceptable and having a MBPro isn't possible for everyone.

  • Won't let me do desktop mirroring!!!!!!

    i have tried every thing and it says it won't work but help panel says it can. I'm also missing the Arrangement tab in the display preferences. Very Urgent!!!!!!!

    I noticed the creator posted saying he had updated it to work with Tiger. Unfortunately I don't know enough about Applescript Terminal or Firmware to know if the newest change to the OS would effect it. And since reseting the Firmware and on an ibook isn't really an easy task, I'm hoping a friend of mine will take a look at it and tell me if it is still compatible, darn him for being on vacation.
    I'm really hopeful, just don't want to brick my iBook and have to take it apart, though that would be a convenient time to get a bigger hard drive.

  • 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

Maybe you are looking for

  • Question mark on photo on apple tv AND deleted photos showing up

    Ok so the first part of this is probably really obvious, but having spent over an hour on the second part of my problem I give up. So, when you are viewing photos, via home share form my  main mac, onto my apple tv, what does to mean when there is no

  • Order Status listed as "archived"​??

    Just upgarding from 3mbps to 7mbps. My order date is supposed to be complete today, the status indicator online says 100% but it's in grey and says that the order is archived. What the heck is an archived order? Also, it says that an equipment shipme

  • IMac not starting

    My iMac screen does not come on. Yesterday the screen froze and a message told me to turn off the computer. The off button would not work so to shut down I unplugged the unit. After a few minutes I plugged it back in again. I can hear the drive start

  • TM stuck on preparing [number] items

    Hey. My Time Machine usually works fine with my MBP, OS X 10.6.3 and my WD MyStudio harddrive. But for the last couple of days TM has been stuck in "preparing files" mode, where it's supposed to prepare all files before it makes the back up. It's bee

  • IWeb blog squished

    I found that when I publish my iWeb blog with several text boxes, HTML snippets, and pictures it does not display properly. The items tend to run together and cover each other up. This problem is especially bad when viewing the posts on iPhone. My po