Apple script hang up

When i run an applescript it does it's job (runs a shell script) but then hangs up and i have to force quit it. Is there a shell script or apple script i could run to tell it to force quit without knowing the number of the running process? This is as i would like to not have to find out the process id number each time i run the script as it changes each time...
thanks - 7;^')

There are two elements here.
First, AppleScript is, indeed, waiting for the process to finish before ending itself, so the first step would be to have AppleScript not wait for the process to end and return control immediately.
In order to do that you need to add some addition elements to the shell command, specifically " > /dev/null 2>&1' before the trailing &, like:
<pre class=command>do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.a pp/Contents/MacOS/ScreenSaverEngine -background >/dev/null 2>&1 &"</pre>
These additional elements suppress the output of the command (which you don't care about anyway) and allows AppleScript to continue while the shell command continues to execute in the background.
For the kill element there is an additional part, echo $!, you can use that returns the PID of the command just executed. You can store this and use it later to kill the process.
This example launches the screensaver for one minute, then kills it.
set myPID to do shell script "/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.a pp/Contents/MacOS/ScreenSaverEngine -background &> /dev/null & echo $!"
delay 60
do shell script "kill " & myPID
You could also use killall, but since this kills processes by name, not PID, you run the risk of killing other processes at the same time.

Similar Messages

  • Apple script force quit

    When i run an applescript it does it's job (runs a shell script) but then hangs up and i have to force quit it. Is there a shell script or apple script i could run to tell it to force quit without knowing the number of the running process? This is as i would like to not have to find out the process id number each time i run the script as it changes each time...
    thanks - 7;^')

    Post to the AppleScript forum under OS X Technologies. IIRC, you can add a quit to the script after some delay time.

  • Sending email using apple script...

    I have created a watch folder using apple script that when a file is dropped on it, it automatically opens, formats, and sends out a custom email.
    What I don't understand is, how can I include multiple variables in the "content" section (also known as the body section of the email)? I want to put custom type in the content section that says "There is a file awaiting your review." I also would like to choose an email signature from my mail program to use. Third, I would like to include the name of the file that is being sent....
    I found that by doing {content:iteminfo} I could get the file name...If I do {content:"There is a file awaiting your review."} I could get the custom type I wanted....
    BUT, I can't figure out how to get BOTH of them together in ADDITION to adding a custom email signature...
    I know there are some really smart people out there...Any tips?

    I can't figure out how to get BOTH of them together
    This is just standard AppleScript text concatenation with the &:
    ... {content: "There is a file awaiting your review: " & iteminfo}
    Here you can see I'm concatenating a literal string (enclosed in quotes) and a variable. You can extend this ad infinitum.
    As for the signature:
    tell theMessage to set message signature to signature "My Sig"
    (which assumes you have a signature named 'My Sig'. Adjust as necessary.

  • New to apple script...

    Hi I am new to apple script; I was using Automator but it became too dumb to it's surroundings after a while. Can you please tell me why these don't do what I think they should; Safari has 2 windows open one with four tabs (window 1 as I have used exists to be sure of) and one with 9 (window 2).
    tell application "Safari"
    activate tab 6 of window 2
    end tell
    all it does is bring the frontmost safari window up
    Please help

    There are a couple of reasons behind this, mostly because you're using the wrong command.
    The main thing is that the 'activate' command is used to activate the application. Any other parameters (such as 'tab 6 of window 2') are discarded.
    Instead, the appropriate syntax is to set the current tab property of the window:
    tell application "Safari"
      set current tab of window 2 to (tab 6 of window 2)
    end tell
    It's a little verbose, but it works.
    If you also want to bring that window frontmost you need to change its index:
    tell application "Safari"
      tell window 2
        set current tab to (tab 6 of window 2)
        set index to 1
      end tell
    end tell
    Note though that changing the window index will now also change this window to 'window 1' instead of 'window 2'. Something to bear in mind if you're taking further actions.

  • How can I get the size of a file with apple script

    I try to get the size of a file within an apple script. But I did not find information how to do this.

    There are two ways. I think Apple is moving toward using System Events, which is listed first.tell application "Finder"
    set myFile to selection as alias
    --this just gets a file for me to work with
    --coercing it into an alias is required for the other functions
    end tell
    tell application "System Events"
    get size of myFile
    end tell
    set myInfo to (info for myFile)
    get size of myInfo

  • How to call a perl script from an apple script

    Hi All,
    How to Call a perl Script from an apple script.
    Pls Give Your comments.
    Thanx & Regards,
    Esther

    Applescript to call a perl script named "/tmp/x.pl" passing an argument "world"
    do shell script "/usr/bin/perl /tmp/x.pl world"
    or if the script is given the executable atttribute (chmod +x /tmp/x.pl),
    do shell script "/tmp/x.pl world"
    Perl script "/tmp/x.pl" that prints a string using a passed argument
    #!/usr/bin/perl
    print "Hello $ARGV[$1]\n";

  • How to disable the option of "Overprint [Black] Swatch at 100%" in Indesign by Apple Scripting

    Hi Friends,
    I am new to Indesign Scripting by Apple Script. As a beginner, I am trying to do some basic scripting in Indesign by Apple Script.
    My aim is to disable the option of "Overprint [Black] Swatch at 100%" in Indesign. This option is available when we go to Indesign ---> Preferences----> Appearance of Black.
    Also, if a user opens a file, in which the swatch is already enabled, then it should prompt him for disabling.
    I can make a display dialog in AppleScript. But, I am bit unsure as how can I go ahead and disable this option. I tried this below script:
    tell application "Adobe InDesign CS4"
          tell every layout window to set overprint preview to false
    end tell
    However, it is changing the view option to overprint preview.
    Appreciate your help and suggestions!
    Thanks,
    Abhishek

    tell application "Adobe InDesign CS5"
              tell the active document
                        set overprint black of document preferences to false
              end tell
    end tell

  • Apple script is stuck working with Numbers

    Hello, everyone
    I need some help.
    I wrote a script what was supposed to do perform following:
    I receive a Numbers-format file imported to my Mac from iPad with iTunes
    This file is a sort of daily journal. Every row includes info about one particular client. A name of the client is in column 2. The file name is always "Blank.numbers" and the table name is always "Blank". I need to copy this table in a new file and collect the data for each client in a different table . In other word i need to make new tables in a new file and copy client info in its own table.
    The script is below. It seems to work right (it makes a new file, makes some tables, puts correct info into them) but one thing happens  - it's stuck in a little while after run. Sure, I reloaded my Mac and not ones but nothing at all - zero effect, the same thing happened over again, after the script successfully worked it  was stuck and i just could see "running". My test data file consists of just up to 40 rows, but I've never had this work completely done. 
    Not much scriptwriter of myself - it's just my very first experience in the subject and I have no clue about why it could be, so I'll appreciate for any suggestion
    on run
         set FileName to "Blank.numbers"
         set ClientColumn to 2
         set CashFlowSheetName to "Cash Flow"
         tell application "Numbers"
              activate
              set FileName to "Blank.numbers"
              set ClientColumn to 2
              set WorkDocument to my makeAnNumbersDoc("Blank.nmbtemplate")  -- creating a new file
              tell document WorkDocument to tell sheet 1
                   set name to CashFlowSheetName
                   delete table 1
              end tell
              set Clients to my GetListOfClients(FileName, ClientColumn) -- getting full list of the clients
              repeat with i from 1 to count of Clients
                   set FullCopy to my GetTable("Blank.numbers", item i of Clients, ClientColumn)  -- choosing data
                   my MakeTable(WorkDocument, CashFlowSheetName, FullCopy, item i of Clients) -- making table with name of  a client for every client
              end repeat
         end tell -- numbers
         return my GetListOfClients(FileName, ClientColumn) -- test line, del me!
    end run
    on MakeTable(WorkDocument, WorkSheet, DataList, Client)
         local i, j
         tell application "Numbers"
              tell document WorkDocument to tell sheet WorkSheet
                   make new table with properties {row count:count of DataList, column count:count of item 1 of DataList, name:Client}
                   tell table Client
                        repeat with i from 1 to row count
                             repeat with j from 1 to column count
                                  set t to value of item j of item i of DataList
                                  if class of t is date then set t to t - (time to GMT)
                                  set value of cell j of row i to t as text
                                  --say "column"
                             end repeat
                        end repeat
                   end tell -- table
              end tell -- sheet
         end tell -- Numbers
    end MakeTable
    on GetListOfClients(FileName, TargetColumn)
         local i, FullListOfClient
         tell application "Numbers"
              open ":Users:Master:Documents:" &amp; FileName
              set FullListOfClient to {}
              tell document 1 to tell sheet 1 to tell table 1
                   repeat with i from 2 to count row
                        if value of cell TargetColumn of row i is not in FullListOfClient then copy value of cell TargetColumn of row i to the end of FullListOfClient
                   end repeat
              end tell
         end tell
         return FullListOfClient
    end GetListOfClients
    on GetTable(DocName, TargetValue, TargetColumn)
         local RowCounter, CopyRow
         tell application "Numbers"
              tell document DocName
                   tell table 1 of sheet 1
                        set RowCounter to 1
                        set CopyRow to {}
                        copy cells of row 1 to the end of CopyRow
                        repeat with RowCount from 1 to row count
                             if value of cell TargetColumn of row RowCounter is equal to TargetValue then
                                  copy cells of row RowCounter to the end of CopyRow
                             end if
                             set RowCounter to RowCounter + 1
                        end repeat
                        return CopyRow
                   end tell
              end tell
         end tell
    end GetTable
    --=====
    Creates a new Numbers document from Blank.template
    and returns its name.
    on makeAnNumbersDoc(myTemplate)
         local t, n
         set theApp to "Numbers"
         set t to ((path to applications folder as text) &amp; theApp &amp; ".app:Contents:Resources:Templates:" &amp; myTemplate &amp; ":") as alias
         tell application "Numbers"
              set n to count of documents
              open t
              repeat
                   if (count of documents) > n then
                        exit repeat
                   else
                        delay 0.1
                   end if
              end repeat
              set n to name of document 1
         end tell -- theApp
         return n
    end makeAnNumbersDoc

    Hello
    Then I have no idea why the script hangs after it has done the job.
    Some thoughts.
    • Is it the same in different user account?
    • If you force quit the script, is the resulting new document fine? In other words, is the problem limited to the termination of the script? You can quit a running script by means of i) pressing command + period, which will signal to cancel the execution of the script or ii) killing the process (editor or applet) by Activity Monitor.
    Anyway, I have done some clean up and optimization of your script as listed below although I can see no reason for these changes to solve the current issue. It is just for my testing and liking for low energy consumption.
    Script is revised so that -
    a) it gets the template path indepent of the location of Numbers.app;
    b) it reduces the number of AppleEvents to send for retrieving data from table by means of range reference form (e.g., rows i thru j) and whose filter reference (e.g., rows whose cell i's value = x);
    c) its GetTable() handler now returns 2d arary of values instead of cell references so that it can reduce the number of AppleEvents for dereferencing the cell reference later;
    d) it introduces _main() handler to localise the implicit global variables in run handler (as already explained);
    e) in _main() handler, code is encapsulated in an script object and the script object is executed by "run script" command, which is a known technique to speed up the execution of script when saved as applet. (Actually this only makes the applet run as fast as compiled script run in editor. Without this, applet runs remarkably slower than run in editor.)
    Hope this may be of some help.
    Good luck,
    H
    on run
        _main()
    end run
    on _main()
        script o
            set FileName to "Blank.numbers"
            set ClientColumn to 2
            set CashFlowSheetName to "Cash Flow"
            tell application "Numbers"
                activate
                set WorkDocument to my makeAnNumbersDoc("Blank.nmbtemplate") -- creating a new file
                tell document WorkDocument's sheet 1
                    set name to CashFlowSheetName
                    delete table 1
                end tell
                set Clients to my GetListOfClients(FileName, ClientColumn) -- getting full list of the clients
                --return Clients
                repeat with i from 1 to count of Clients
                    set FullCopy to my GetTable(FileName, item i of Clients, ClientColumn) -- choosing data
                    --return FullCopy
                    my MakeTable(WorkDocument, CashFlowSheetName, FullCopy, item i of Clients) -- making table with name of a client for every client
                end repeat
            end tell -- numbers
            return Clients -- test
        end script
        run script o -- # this will dramatically speed up the execution of script when saved as an applet
    end _main
    on MakeTable(WorkDocument, WorkSheet, DataList, Client)
        local utc_offset, rk, ck
        set utc_offset to time to GMT
        set Client to Client as string -- for safety
        tell application "Numbers"
            set rk to count DataList
            set ck to count DataList's item 1
            tell document WorkDocument's sheet WorkSheet
                make new table with properties {row count:rk, column count:ck, name:Client}
                tell table Client
                    repeat with i from 1 to rk
                        repeat with j from 1 to ck
                            set t to DataList's item i's item j
                            if class of t is date then set t to t - utc_offset
                            set row i's cell j's value to t as text
                        end repeat
                    end repeat
                end tell -- table
            end tell -- sheet
        end tell -- Numbers
    end MakeTable
    on GetListOfClients(FileName, TargetColumn)
        local FullListOfClient
        tell application "Numbers"
            --open (":Users:Master:Documents:" & FileName) as alias
            open ((path to documents folder from user domain as text) & FileName) as alias
            --open ((path to desktop as text) & FileName) as alias -- for test
            set FullListOfClient to {}
            tell document 1's sheet 1's table 1
                repeat with c in (get value of cell TargetColumn of rows 2 thru -1)
                    set c to c's contents
                    if c is not in FullListOfClient then set end of FullListOfClient to c
                end repeat
            end tell
        end tell
        return FullListOfClient
    end GetListOfClients
    on GetTable(DocName, TargetValue, TargetColumn)
        local CopyRow
        tell application "Numbers"
            tell document DocName's sheet 1's table 1
                set CopyRow to value of cell of rows whose cell TargetColumn's value = TargetValue
                set CopyRow's beginning to value of cell of row 1
                return CopyRow
            end tell
        end tell
    end GetTable
    --=====
    Creates a new Numbers document from Blank.template
    and returns its name.
    on makeAnNumbersDoc(myTemplate)
        local t, n
        tell application "Numbers"
            set t to (((path to resource "Templates") as string) & myTemplate) as alias
            set n to count documents
            open t
            repeat until (count documents) > n
                delay 0.1
            end repeat
            return name of document 1
        end tell
    end makeAnNumbersDoc

  • Install and uninstall of dmg file using Apple script in Mac 10.6 and higher version.

    Hi ,
    Could anyone please help me to write a Apple script to Install dmg file and do clean uninstall in Mac 10.6.8 and higher version.
    My requirement is:
    When i run script : it has to install the dmg file which is located inside one desktop folder say 'New Folder'
    I need to do clean unistall when i run the script: i need to delete the folder in ~/Library- locate folder say  'CPSPCSHOWSERVER'' move to trash and from Terminal type in command "rm -r ~/.CPS' to completely delte this folder.
    Really appreciated all ur help!!
    Thanks,
    KT.

    http://macfidelity.de/2008/08/30/how-to-mount-a-dmg-from-terminal-in-mac-os-x/in dex.html
    http://osxdaily.com/2011/12/17/mount-a-dmg-from-the-command-line-in-mac-os-x/
    http://hints.macworld.com/article.php?story=20030614230204397
    http://www.commandlinefu.com/commands/view/2031/install-an-mpkg-from-the-command -line-on-osx

  • How do I stop Apple Script from leaving a Text.txt file with each image downloaded using Photo Downloader in Adobe Photoshop CS4_Bridge???

    I use Adobe Photoshop CS4_Bridge _Photo Downloader to import images from CF Cards into my 11" Mac Book Air.  I have an issue with the Text files
    that seem to accompany each and every image that I do not need.  How do I stop Apple Script (which I assume is the culprit in this case)  from interferring with this process.

    Your iWeb Site is stored not on your iDisk, but on a file named Domain.sites in your ~/Home/Library/Application Support/iWeb/ Folder.
    If , for whatever reason, you wipe your HD and/or lose this file (Get a new computer, Re-Install your OS, Stolen Laptop, Crashed HD, Etc.) without backing-up your Domain.sites file then you will have to re-build your iWeb sites from scratch again.
    Of course you can edit your Published HTML files in a different program such as Dreamweaver or even Text Edit. You just can't edit Published HTML files in iWeb. Not at this time at least.
    Use iWebBackup to backup your Domain file to a Blank CD or DVD. Backing up your Domain file to another folder on your computer is not fully backing it up. If your computer gets stolen you still lost the file but if you have your Domain file burned onto a CD you have a backup!
    Download iWebBackup Here
    You can use iWebExtender to automatically consolidate your files into one folder and delete multiple images.
    http://iWebFAQ.com

  • Can I use Apple Script to press a button?

    Is there some way I can create an Apple Script to run and press a button in another application, or create a "plug-in" type script for the program to make the button into a something that can be used by a keyboard shortcut?
    I ask because I have an application that I can use to operate my digital camera, however, the button that Auto-Focuses then Shoots a photo does not have a keyboard shortcut. This is a problem because I also have the App "Snatch" on my iPhone, and, long story, short, I discovered I could use Snatch on my laptop on an Ad-Hoc network from about 1,000 feet away, maybe more. If I could find a way of making the "AF and Shoot" button into a keyboard shortcut, or create a script that could be triggered by a keyboard shortcut to press the button, I could use Snatch to control my camera remotely, far better then any part I would by from Nikon, or a third-party (Trust me, I have used a lot of them, and this method beats them all, save for the fact that I can't use bulb.)
    Anyway, thanks for any input, if any.

    Even if an application is not scriptable, you can generally use [GUI Scripting|http://www.macosxautomation.com/applescript/uiscripting/index.html] to press a button. For example, using Canon's RemoteCapture DC software, the script below will press the "Release" button of the main window:
    tell application "RemoteCapture DC" to activate
    tell application "System Events"
    tell process "RemoteCapture DC"
    click button 4 of window "RemoteCapture DC"
    end tell
    end tell
    If you then put the above script in the AppleScript menu in the menu bar, you should be able to use a third party application, like Quicksilver, to assign a keyboard shortcut to it.
    Message was edited by: Pierre L.

  • How to check indesign version installed by Apple Script

    Hi Friends,
    I want to make an apple script which will check for the version of Indesign installed in the "Applications" folder.
    I tried using "exists" function of Finder. But seems something is missing/incorrect.
    tell application "Finder"
              exists application file "Adobe InDesign CS4" of folder "Applications"
      end tell
    Please can you suggest.
    Thanks,
    Abhishek

    Hi Niel,
    Thanks for your email.
    Basically, I need to check whether a user has which version of Indesign on his mac like (CS3, CS4 etc)
    Accordingly, I have to create different loops.
    I have CS4 installed on my mac but when I run the below
    tell application "Finder"
              exists version of application file "Adobe InDesign CS4" of folder "Applications" of startup disk
    end tell
    The result is false.. even though I have CS4 installed. And, if I try
    get version of application "Adobe InDesign CS4"
    It gives o/p as  "6.0.6.622"
    Thanks for your help!
    Abhishek

  • Apple Script for indesign

    Hai all,
    i am trying to insert footnote and its contents for a particular xml element in "Adobe Indesign cs2" thru apple script. But i'm facing some problem. I'm able to select the xml element and its contents and i can insert footnote for that element and i can cut that contents but i couldn't paste this contents in footnote. I have tried with the following code:
    tell application "Adobe InDesign CS2"
    tell active document
    set theRoot to (item 1 of XML elements)
    end tell
    end tell
    myLoopLoop(theRoot)
    property myLoLoV : {}
    property myHoHoV : {}
    on myLoopLoop(myElement)
    tell application "Adobe InDesign CS2"
    tell active document
    set moreElement to every XML element of myElement
    repeat with x from 1 to (count of moreElement)
    set em1 to item x of moreElement
    select em1
    if (name of markup tag of em1 is "informalexample") then
    set em2 to em1
    select text of em2
    tell insertion point 1 of em1
    set myfootnote to make footnote
    end tell
    tell application "Adobe InDesign CS2"
    set myselection to selection
    cut (selection of active document)
    end tell
    tell application "Adobe InDesign CS2"
    tell insertion point 1 of myfootnote
    paste into myfootnote
    set text of em2 to myfootnote
    end tell
    end tell
    end if
    tell me to myLoopLoop(item x of moreElement)
    end repeat
    end tell
    end tell
    end myLoopLoop
    Can anyone help me out to sort this problem?
    Thanks
    anbu
    I Mac   Mac OS X (10.4.8)   Intel based Mac

    hi all
    any help
    thanks
    anbu

  • Using c++ variable in apple script

    Hi all,
    I am just calling the apple script from my indesign plugin.
    I need to pass the c++ variable to apple script for opening a file
    This in my apple Script which i have embedded in c++ code
    tell application "TextEdit"
    activate
    open "Users:User1:Library:Preferences:Adobe Indesign:Version 5.0:MathEQ.txt"
    end tell
    The filepath "Users:User1:Library:Preferences:Adobe Indesign:Version 5.0:MathEQ.txt" is stored in the C++ variable char* textFileName.
    I need to use the variable textFileName in apple script which has the path.
    How to go about it?
    Thanks
    Sakthi

    I have a similar problem trying to get data from any field into an AppleScript variable.
    Something like *set phoneNumber to cell "Phone Number" of current record* works fine if you are using the script from a layout that has this field on it.
    But I have a lot of fields on different layouts and I want to have access to all fields in the table, no matter what layout they are on, or what layout is currently active.
    And I want to do this without having to specify on what layout each field is located.
    In the past (FileMaker 6) I used something like *set phoneNumber to (cell "Phone Number" of current record of database 1)* but this is no longer working in FileMaker 9.
    So I was thinking to use something like *set phoneNumber to cell "Phone Number" of current record of table "Table Name"* but that doesn't seem to work.
    The only thing that seems to work is *set phoneNumber to cell "Phone Number" of current record of layout "Layout Name"* but as I said, I don't want to specify the layout for each field.
    Any ideas anyone?
    Message was edited by: khasmir

  • Find raster Image & Vector image in adobe indesign using apple script?

    Find raster Image & Vector image in adobe indesign using apple script?

    Find raster Image & Vector image in adobe indesign using apple script?

Maybe you are looking for

  • IOS 8 RAW Support - Photos Resized

    Can anyone else confirm this possible bug? Importing JPG+RAW files using the Camera Connector on iOS 8 resizes the RAW files to the exact same file size as the JPG. This ends up being about a 50% reduction in RAW file size. At this point I have no id

  • Missing Bcc: functionality in Tiger Mail--and worse: no Bcc: button!

    MISSING IN ACTION! Pre-Tiger, if you wanted to include a bunch of Bcc: addresses from your Address Book within Mail you could double-click each one from the mini Address Book window IF YOU HAVE THE CURSOR in the Bcc: field. Even worse is that since M

  • Query across two facts with filter on unconformed dimension

    Hi This question is actually regurgitated from another post as I wrongly tagged it onto the end of an already answered question. Anyway, I am trying to query across 2 fact tables which have a dimension in common (conformed) and also some dimensions t

  • Using background-size: cover causes Edge Animate to crash

    Bug report: If I select an element which has background-size tag specified for the element I get "An error occurred. Please save your work and restart Edge Animate." This happens background-size: cover, background-size: contain, etc.

  • Trying to create two form buttons side by side?

    Hi all... Kind of a strange question...  I've been messing around with this one for way too long now and thought I'd seek your help... Anyway,  one <form> with two submit buttons on them.  One is a "submit" button and the other is a "cancel" button.