How can I run a script when an application quit??

Greetings all,
I'm trying to write a script, which can be triggered automatically (to do some stuff) at the time when a given application quit. I was playing around with this test script, taking "TextEdit" as an example - it just prints a message when TextEdit exits.
==========================================
+*set targetapp to "TextEdit"*+
+*tell application "System Events" to set rr to name of the processes*+
+*--if targetapp is not in rr then*+
+*-- tell application targetapp to activate*+
+*-- tell application "System Events" to set rr to name of the processes*+
+*--end if*+
+*set rr1 to rr*+
+*repeat until rr1 ≠ rr and targetapp is not in rr1*+
+*tell application "System Events" to set rr1 to name of the processes*+
+*do shell script "sleep 1"*+
+*end repeat*+
beep
+*display dialog (targetapp & " is not active anymore !") as string buttons {"OK"} default button 1 with icon 0*+
============================================
Unfortunately, it seems to work if I launch TextEdit using the script itself; it doesn't work with first +*"if - end if"*+ block commented out. Does anyone know how can I achieve this? Any help or suggestion greatly appreciated. Cheers!!

Hi santanu,
I'm sure you can use a variation of this application of mine to do what you want. It monitors all running processes and then reports when one closes.
--initialize previous_processes
global previous_processes
tell application "Finder"
set previous_processes to get the name of every process --use "whose visible is true" to remove the background ones
end tell
--monitoring script
on idle
tell application "Finder"
set current_processes to get the name of every process
end tell
set numberofprocesses to count of items in previous_processes
set counter to 1
repeat while counter is less than (numberofprocesses + 1)
if current_processes does not contain item counter of previous_processes then
display alert item counter of previous_processes & " quit!"
end if
set counter to counter + 1
end repeat
set previous_processes to current_processes
return 1 --runs every second...can be changed
end idle

Similar Messages

  • How can i run unix script from my apex page

    how can i run unix script from my apex page and take the output of unix script as a hidden variable and display it on the report region of that page

    I had a requirement to run a Fortran program against some data that woudl be extracted from the database after the user set up their filtering criteria and made some additional input. SInce the program was to complex to conver to PL/SQL, we decided to try and invoke it from Apex. This is how I did it.
    1. I followed the steps in Tim Archer's excellent article "Oracle External Procedure to Run Host Commands" (http://www.timarcher.com/?q=node/9). If the link does nto work, google the article's title.
    Using this steps I created a function which accepts any OS command, including calling my own shell scripts, and runs them. I called my PL/SQL function "shell" instead of "USF_RUN_HOST_CMD " as Tim did in his example (step 9).
    2. In Apex,
    a. I created a button to run my shell command. (I named it P2_RUN_SHELL)
    b. I created a PL/SQL process whose source looks as follows:
    shell('/home/ackness/scripts/cr_xcf_file.sh > /tmp/cr_scfp_file.log');
    and which was conditioned on the the button P2_RUN_SHELL.
    It works like a charm.
    Note: since you can run your own scripts using this method, you can encapsulate a series of commands in a UNIX shell script and invoke that script from Apex. This allows you to be able to test or run you commands from the command line as well as Apex and makes it easier to develop/debug/enhance the scripts in the future.
    Ackness

  • Launchd - can it run a script when users log in OR switch?

    I'm hoping to find someone who knows all the gory details of launchd. Here's the why and what: I'm trying to coerce Aperture into letting two users on the same computer share the same Aperture Library, both able to import photos and see and use what the other has done. Initially it is no problem, change the permissions so everyone has read/write/execute, put the Library in a common area, and point both person's Aperture at it. The problem is that Aperture changes permissions of things inside the Library as you use it, and especially when one person imports, the other person can't see that stuff.
    So I want to run a script whenever someone logs in or becomes the active user by fast user switching; the script will simply change ownership and permissions of the library and everything in it to restore full access.
    After days of research and testing, I made a test launchd plist file (this is the configuration file or agent that launchd looks at and runs your script when criteria are met). It sits in /Library/LaunchAgents/, here it is:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>org.jim.test</string>
    <key>LimitLoadToSessionType</key>
    <string>LoginWindow</string>
    <key>ProgramArguments</key>
    <array>
    <string>/Library/Scripts/testscript.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/Users/jim/Desktop/test.err</string>
    <key>StandardOutPath</key>
    <string>/Users/jim/Desktop/test.out</string>
    </dict>
    </plist>
    The actual test script is sitting in /Library/Scripts/:
    #!/bin/bash
    echo "org.jim.test.plist was run at `date`"
    So if the plist is loaded and the script run, the date and time are written in the test.out file on my desktop. This thing runs great when a user logs in. The problem is, it doesn't run when users switch by fast user switching. In reading the documentation, it was vague about this, whether that could be done; I thought it could.
    Can anyone help with a way to get the script to run when any user takes control by any means? As an added complication, which I'll worry about later, the script has to run as root because it's the only way to get the ownership and permissions changed.
    Thanks,
    Jim

    BobHarris is the MAN. ACLs seem to have worked. I put the Aperture Library in /Users/Shared/ApertureLibrary, restored the regular permissions as best I could (me as owner, staff as group, 755), pointed each person's Aperture to the library, then proceeded with the ACL magic. First I created a group for my wife and I, called 'aperture', in the Accounts preference pane. That was to simplify the ACLs (one entry instead of 2) and so that other users (son) aren't able to muck it up.
    It took one stinking Terminal command (note that 'aperture' at the beginning of the quote is the group, not the program, folder or library):
    chmod -R +a "aperture allow list,addfile,search,delete,add_subdirectory,delete_child,file_inherit,directoryinherit" ApertureLibrary.aplibrary
    I was unsure whether this list of permissions was necessary or sufficient, but it seems to have worked so far. Both users can access the library. I imported a different picture by each user, and the other user could then see and delete the picture imported by the other. This was not possible before.
    Bob, thanks for the great idea. After a little more testing I'll post a complete how-to in the latest "how do we share Aperture" thread, and give you due credit. The bad news is all the launchd fun is over
    Jim

  • How can I run a script on suspend/resume?

    I'd like to run a script when a machine is about to suspend and another after it resumes. Is this possible?

    You can pipe the results of Out-Command to Out-File (or Export-Csv, etc.)  I'm not sure what kind of objects you're expecting from this script, so I'll err on the side of caution and use Format-List * in the example:
    Invoke-Command -ComputerName $servers -FilePath c:\copy.ps1 |
    Format-List -Property * |
    Out-File -FilePath $home\Desktop\copy.log

  • How can I run a script last?

    Hiya,
    I have a single backup job running a single dataset. That single dataset has an include statement to include a dataset directory, which holds individual datasets for the several hosts I want to back up, each with potentially different parameters. This works well, the hosts back up in some order (I don't care), everything's happy.
    However, what I want to do is add a step on the end of this process to run a report on the admin server after all the backups are complete. That is, to run a script once, last.
    If I add an "after backup" command in the dataset, it runs it (as stated in the manual) on the client servers, after every backup, which is no good to me. I've tried creating a separate job and scheduling it at a lower priority a few minutes later than the backup job, but that seems to just run when it feels like it, I presume because there aren't any conflicts so why shouldn't it?
    Can anyone advise how I should be doing this?
    Related question... I've tried putting an "after backup" step on the Catalog backup job, but that appears to get run twice (I presume because there are two "include" steps in the catalog dataset)! Is this expected? How can I get it to just run once, after the catalog backup is complete?
    Thanks,
    David.

    Thanks Donna, but... no. It didn't work.
    We've actually purchased a license for OSB, so I've fired this question at our official support channel now, and they came back with the same answer at the same time (are you the Oracle techie looking at my problem, by any chance?). For the record here's (with some tweaks for readability in this context) what I've sent back in response to that article.
    From the article, I thought perhaps the following might do the trick:
    include dataset /Hosts {
    after backup optional "/usr/local/osb/pre-n-post after-fsd-hosts mail"
    But, from the log:
    2010/11/05.07:26:58 trouble parsing dataset in FSdaily line 1 - open brace appears where not allowed (OB dataset mgr)
    "010/11/05.07:26:58 offending line is "include dataset /Hosts {
    2010/11/05.07:26:58 trouble parsing dataset in FSdaily line 3 - bad nesting (OB dataset mgr)
    "010/11/05.07:26:58 offending line is "}
    So it appears I’m not actually allowed to do that. I don’t understand why that would be.
    The only other idea I have is to include a dummy backup step, backing up something really small (because OSB won’t let you run a backup without backing anything up - sigh!), tack a script onto that, and hope like heck OSB decides that it should run that last. All the documentation I’ve read gives the impression that datasets are all about scope, not order, so I’m not altogether confident that this will work. In any case, it seems a pretty kludgy way of doing it! And, given the next paragraph below, I’m not all that sure it’ll work in any case.
    My idea of scheduling a catalog backup for five minutes later than the client backups, with a lower priority, so that it runs when the client backups finish, also has a flaw - if I use two tape drives in parallel, it runs the catalog job in parallel with the last client job, which is completely useless. I want to put on the end of the tape a backup of the catalog as at just after the client backups, so that in the case of a disaster I can restore that and I’ll be good to restore everything else.
    In addition to being completely useless for the purposes of putting an “after” catalog backup on the end of the tape, it’s also completely useless for the purposes of running a script last - I tried the following:
    include catalog {
    after backup optional "/usr/local/osb/pre-n-post after-catalog mail"
    This ran the pre-n-post script twice, once for each component of the catalog, which is altogether not what I want it to do.
    I can’t think of any way to achieve a catalog backup on the end of the script except for scheduling it for some time later and hoping the dataset backups always finish by then. Ugly.
    The only way I can think to achieve the run-a-script-last is to munge all the datasets together into one humongous dataset file, and do stuff as in the article to try to bend OSB to my will (again, hoping that OSB obeys the order of statements in the dataset). Which, when I’m given the ability to use “include dataset /Hosts” to make it easy to maintain, seems a bit of a mean trick to pull on me. And, again, with two tape drives available I’m not at all sure it’ll work in any case.
    I'll post further results as they come to light...
    David.

  • How can I run a script from path?

    Hi all
    How can a illustrator script be run from a path by double clicking the script file not from illustrator menu->scripts.
    thanks in advance
    THAMIL

    You can modify the script to use COM.  For example, when the script is run in AI, there is an assumed application object - you can just use the members of the Application object without having an explicit Application variable.  To do this in a standalone javascript, create a Illustrator.Application object:
    var app = new ActiveXObject("Illustrator.Application");
    var activeDoc = app.activeDocument;
    You would do something similar for any object that would otherwise need to be created with new.  You can get a list in the the registry - HKCR\Illustrator.*
    Note that .length and collection[i] don't work when you do this.  Use .count instead of .length.  You need to use Enumerators:
    var textEnum = new Enumerator(doc.textFrames);
    for (; !textEnum.atEnd(); textEnum.moveNext()) {
        var txt = textEnum.item();
        txt.contents = "text";
    You also have to use WScript.Echo() instead of alert().
    Phil

  • How Can I run a script to all servers in my servers list

    Hi Guys
    I have a Servers list:servers.txt , it's including all servers i need to run a powershell script,how can I use the powershell to run a script on those servers? thank you.I just start to learn about powershell.

    You can pipe the results of Out-Command to Out-File (or Export-Csv, etc.)  I'm not sure what kind of objects you're expecting from this script, so I'll err on the side of caution and use Format-List * in the example:
    Invoke-Command -ComputerName $servers -FilePath c:\copy.ps1 |
    Format-List -Property * |
    Out-File -FilePath $home\Desktop\copy.log

  • How can I run an applet from an application (frame)?

    I have an application (frame) that render images and save it, and then I want to create an animation with those images using Animator applet from the application itself, but I do not how to call the applet from the application, is this possible?
    Thanks in advance, Jorge

    You can simply run a JApplet in a JFrame. Just create a frame object, an object of your applet, add the applet to the frame and call the init() function of your applet. It could look like this:
    JFrame anyFrame = new JFrame("MyTitle");
    YourApplet yourApplet = new YourApplet();
    anyFrame.getContentPane().add(yourApplet, BorderLayout.CENTER);
    yourApplet.init();
    anyFrame.setSize(new Dimension(800,600));
    anyFrame.setVisible(true);
    You will not necessarily have to write the applets default constructor.

  • How can i run wireless internet when using windows xp on my imac?

    I recently installed Windows XP on my imac using Boot Camp, everything works great except the internet. ive been looking but i have found no way to get the internet to work via my wireless connection, or is it just not possible?
    Could it be that i am missing some drivers? Anyone know where i can get them?
    Sorry if im asking too much stuff.
    Thanks in advance

    Depending on the wireless base station brand and specifications,
    you may have to set up the Windows system to find & use it...
    Just about the same as setting up any Windows PC to go online;
    except, if you have an Apple base station...
    If you have an AirPort base station, there are updates for Windows
    to help use that access point, from your Mac, running Windows.
    An example, but not necessarily the correct answer, in the following:
    • AirPort Utility 5.4.2 for Windows
    http://support.apple.com/kb/DL840
    Since you have posted this request in 10.5 Leopard> Automator
    discussion, this won't be a suitable place to find matching replies.
    see: Windows compatible technologies> Airport for Windows:
    http://discussions.apple.com/forum.jspa?forumID=1014
    There are other topic discussions under the Windows area,
    so if you look into the main Discussions page and look into
    the bottom of the listings, you can see the larger group there.
    Apple Support Discussions - Forum Home:
    http://discussions.apple.com/index.jspa?categoryID=1
    Perhaps after reading through topics in the Windows> Airport
    thread, you may wish to reconstruct and repost it in that area.
    Good luck & happy computing!
    { edited to add Airport Utility info & misc explanation }

  • How can configure the default page when the application startup?

    I would like, when i published my application in weblogic, write the context root and automatically start my first page.
    For examples, I have 3 pages in ADF project. The names are: a.jspx, b.jspx and c.jspx
    When I publish I see in Jdeveloper:
    The following URL context root(s) were defined and can be used as a starting point to test your application:
    [02:15:30 PM] http://localhost:7101/myapplication-ViewController-context-root
    but when I write this link in my browser I get an error (404 not found).
    I try http://localhost:7101/myapplication-ViewController-context-root/faces/ but I get the same error.
    I would like that a.jspx runs automatically when I write the context, is possible?
    In adfc-config.xml I just use control-flow-role and in "From Activity ID" i wrote * and in control-flow-case in "To Activity ID" I wrote a.jspx but I think this need when I come to other pages where i do not use outcome and is not correct for the first time when I run the application, is it?.
    Thanks

    I put the view component and in its property Page I wrote /a.jspx but nothing.
    When I deploy in and type http://localhost:7101/myapplication-ViewController-context-root/faces/ the application server change to http://localhost:7101/myapplication-ViewController-context-root/faces/?...
    I don't know where is the mistake.

  • How can I run other application?

    Hello everyone!
    I have few questions, for example I use this to run other application:
    Runtime.getRuntime().exec("C\\Program Files\\Opera\\Opera.exe");1. It works, but how can I run Opera.exe, when I don't know where was install Opera?
    2. I want open URL, but I don't care what browser will be use. How do this?
    p.s.
    I hope, you will understand my English =)

    In Windows, to open a URL in the default browser you simply use the START command, like this:START http://www.canadiantire.ca/Try that at the command line. You can use Runtime.exec() to do this, as has been discussed in several hundred earlier posts in this forum.

  • How can I run a SQL script file...

    How can I run a SQL script file from a location on my computer without providing the whole path?
    Is there some way I can set a "Working folder" in SQL Plus??
    Thanks!
    Tom

    You can create an environment variable called "SQLPATH" which is a list of directories that SQL*Plus will search for your .SQL
    scripts.
    I would like to use another directory than the oracle/bin...
    How can I do this ??
    Hello,
    U can do this by this way:
    Save odm_script.sql file to the default Oracle
    directory i.e. Oracle-Home/bin and Run following command
    through SQL Plus.
    SQL>@Script_Name
    I hope this will resolve ur problem.
    Regards,
    Omer Saeed Khan.

  • How can I run a SubVi in background when a sequence is running in the main VI

    What I want to do is this
    When I push a button on the main VI, a SubVI (#1) must run and take data.
    At the same time, a sequence, in which there are other subVIs must run.
    My problem is that the subVI #1 does not run when I push the button. The sequence is running well. How can I run both the sequence and the subVI at the simultaneously?
    Solved!
    Go to Solution.

    Hey Hugo,
    Sounds like you'll just want to do some parallel loops. I'll attach a screenshot of a VI that has a sequence where the counter goes up to 3, then restarts, each time it reads the iteration count from the subVI above. (The subVI is just a while loop with the iteration count attached to the global)
    Each iteration of the sequence shows an increased count from the subVI via a global variable.
    Is this what you are looking for?
    Keep in mind that I just threw this together to show functionality, its got a lot of rough edges to it.
    Message Edited by Chris_VH on 03-30-2009 03:59 PM
    Chris Van Horn
    Applications Engineer
    Attachments:
    iteration.jpg ‏43 KB

  • Help:How can I run the J2EE Client Application? Thanks

    Help:How can I run the J2EE Client Application that will access the remote J2EE1.4 application server which runs on another host computer?
    I have developped a stateles senterprise java bean name converter and deloyed it in the j2ee1.4 application server on the host machine A. The converterbean provides the remote home interface and remote interface. At the same time I have developped the j2ee application client named convertappclient. When I access the conveter bean at host computer A through the script 'appclient.bat' as 'appclient -client convertappclient.jar', the client can access the bean sucessfully. Now I want to access the bean through the script 'appclient.bat' at host computer B,what files should I copy from host computer A to host computer B;and what the command line should be like? Thanks!
    The following are the code of the enterprise java bean and it's home interface .
    The client code is also provided.
    The enterprise java bean:
    package converter;
    import java.rmi.RemoteException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    import java.math.*;
    public class ConverterBean implements SessionBean {
    BigDecimal yenRate = new BigDecimal("121.6000");
    BigDecimal euroRate = new BigDecimal("0.0077");
    public ConverterBean() {
    public BigDecimal dollarToYen(BigDecimal dollars) {
    BigDecimal result = dollars.multiply(yenRate);
    return result.setScale(2, BigDecimal.ROUND_UP);
    public BigDecimal yenToEuro(BigDecimal yen) {
    BigDecimal result = yen.multiply(euroRate);
    return result.setScale(2, BigDecimal.ROUND_UP);
    public void ejbCreate() {
    public void ejbRemove() {
    public void ejbActivate() {
    public void ejbPassivate() {
    public void setSessionContext(SessionContext sc) {
    The bean's remote home interface :
    package converter;
    import java.rmi.RemoteException;
    import javax.ejb.CreateException;
    import javax.ejb.EJBHome;
    public interface ConverterHome extends EJBHome {
    Converter create() throws RemoteException, CreateException;
    The bean's remote interface:
    package converter;
    import javax.ejb.EJBObject;
    import java.rmi.RemoteException;
    import java.math.*;
    public interface Converter extends EJBObject {
    public BigDecimal dollarToYen(BigDecimal dollars) throws RemoteException;
    public BigDecimal yenToEuro(BigDecimal yen) throws RemoteException;
    The j2ee application client:
    import converter.Converter;
    import converter.ConverterHome;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.rmi.PortableRemoteObject;
    import java.math.BigDecimal;
    public class ConverterClient {
    public static void main(String[] args) {
    try {
    Context initial = new InitialContext();
    System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
                   System.setProperty("java.naming.provider.url","jnp://10.144.97.250:3700");
    Context myEnv = (Context) initial.lookup("java:comp/env");
    Object objref = myEnv.lookup("ejb/SimpleConverter");
    ConverterHome home =
    (ConverterHome) PortableRemoteObject.narrow(objref,
    ConverterHome.class);
    Converter currencyConverter = home.create();
    BigDecimal param = new BigDecimal("100.00");
    BigDecimal amount = currencyConverter.dollarToYen(param);
    System.out.println(amount);
    amount = currencyConverter.yenToEuro(param);
    System.out.println(amount);
    System.exit(0);
    } catch (Exception ex) {
    System.err.println("Caught an unexpected exception!");
    ex.printStackTrace();
    }

    Surprisingly I find an upsurge in the number of posts with this same problem. I recently found a post which gave a nice link for this. Follow the steps and it should help:
    http://docs.sun.com/source/819-0079/dgacc.html#wp1022105

  • How can I write a script for set left indent?

    In three cases as below:
    for example:
    left indent:8mm; first indent:0mm
    left indent:0mm; first indent:8mm
    left indent:8mm; first indent:-8mm
    How can I write a script to tell Indesign, wherever the text indent is, each time when I run the script once, the text can put just a step rightward, and “one step = 8mm”.
    Please!

    Hi, Trevor
    I use change by list as below:
    grep {leftIndent:48mm} {leftIndent:56mm}
    grep {leftIndent:40mm} {leftIndent:48mm}
    grep {leftIndent:32mm} {leftIndent:40mm}
    grep {leftIndent:24mm} {leftIndent:32mm}
    grep {leftIndent:16mm} {leftIndent:24mm}
    grep {leftIndent:8mm} {leftIndent:16mm}
    grep {firstLineIndent:8mm, leftIndent:48mm} {firstLineIndent:8mm, leftIndent:56mm}
    grep {firstLineIndent:8mm, leftIndent:32mm} {firstLineIndent:8mm, leftIndent:48mm}
    grep {firstLineIndent:8mm, leftIndent:24mm} {firstLineIndent:8mm, leftIndent:32mm}
    grep {firstLineIndent:8mm, leftIndent:16mm} {firstLineIndent:8mm, leftIndent:24mm}
    grep {firstLineIndent:8mm, leftIndent:8mm} {firstLineIndent:8mm, leftIndent:16mm}
    grep {firstLineIndent:-8mm, leftIndent:48mm} {firstLineIndent:-8mm, leftIndent:56mm}
    grep {firstLineIndent:-8mm, leftIndent:32mm} {firstLineIndent:-8mm, leftIndent:48mm}
    grep {firstLineIndent:-8mm, leftIndent:24mm} {firstLineIndent:-8mm, leftIndent:32mm}
    grep {firstLineIndent:-8mm, leftIndent:16mm} {firstLineIndent:-8mm, leftIndent:24mm}
    grep {firstLineIndent:-8mm, leftIndent:8mm} {firstLineIndent:-8mm, leftIndent:16mm}
    but not that perfect,
    I want to useing jave "if{}" or "for{}" to write this script, but I don't kown the syntext.

Maybe you are looking for

  • Has anyone found bluetooth headphones that successfully pair with Apple Watch (not Beats)

    I've been trying to pair the Apple Watch with a few different bluetooth headphones including LG and Kinivo without success. Not really interested in buying another set of bluetooth headphones or dropping $200 on them. Any one have success pairing App

  • Vendor Missing on SC when Purchasing from Internal & External Catalog

    Hi All - I have a strange problem and I am wondering if anyone else has run into this and how they solved it.  We are implementing SRM 5.0 on SRM Server 5.5 with SRM-MDM.  We are using both internal catalogs as well as punch out catalogs.  If we sele

  • Server error 503 when running On-demand HTTP Dynamic Streaming tutorial

    Hi, I'm trying to set up an HTTP Dynamic Streaming environment for VoD (not live streaming). I'm following the instructions in the HTTP Dynamic Streaming Quick Start guide (http://help.adobe.com/en_US/HTTPStreaming/1.0/Using/WS8d6ed60bd880807c48597a9

  • Connection problems portal - BI

    Hello, We are trying to connect the BI system with a BI portal (same system).. However, when running the template installer on the portal, we get some errors such as: "Element 'SAPConfigLib.ABT.Unclassified.maintainJcoDestination':Error during execut

  • Re:Copy Condition record

    Is there any solution if I maintain the condition record of particular condition type ,the value of this condition record is auomatically copy to another condition record.