Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 25, 2013, 08:02 PM   #1
DonK KijotE
macrumors newbie
 
Join Date: Mar 2013
Location: Madrid / Spain
Doubts About Running Applescript On Background

Hi,

I'm writing a little Applescript which waits for a window to open in order to close it automatically.

The things is, how can I wait for the window to open? I don't want to run an endless loop which checks for a window with a certain title...

Could anyone give me some directions on how to achieve this in the most efficient way?

Thanks on beforehand, any help would be appreciated!

Cheers
DonK KijotE is offline   0 Reply With Quote
Old Mar 25, 2013, 11:33 PM   #2
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
What window are you waiting for to open?

If your Applescript is opening the window, then I see no issue with just inserting a 0.3 delay after opening the window and having it close the window at that point... I know I've done exactly that before.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed.
Including the ones paired with other Macs on your network.
ArtOfWarfare is offline   0 Reply With Quote
Old Mar 26, 2013, 08:56 AM   #3
DonK KijotE
Thread Starter
macrumors newbie
 
Join Date: Mar 2013
Location: Madrid / Spain
The window is opened by another application.

This window will appear when a user clicks a certain button so, how wait for that without using 100% cpu ?

For testing purposes I put my code into an endless repeat loop and it works, but cycling endlessly through the script is nor efficient nor elegant IMO.

I hope I clarified the script scenario a bit better this time.

Just in case someone thinks I just want someone to code for me that's not the case. Any hints on a workaround/solution will be appreciated, I will investigate further on by myself and update this post so it works as a future reference for others

Thanks again!

Current Loop Code:

Quote:

repeat

tell application "System Events"

if exists window "Window_Title" of process "Target_Process" then

-- Do bla bla bla

end repeat
Window_Title and Target_Process are just substitutes for the real values, as I wouldn't like to give any hints on what I'm working on... Don't wan't any "idea thieves" buzzing around :P

Last edited by DonK KijotE; Mar 26, 2013 at 11:06 AM.
DonK KijotE is offline   0 Reply With Quote
Old Mar 27, 2013, 02:24 PM   #4
Mark FX
macrumors member
 
Join Date: Nov 2011
Is your Aplescript run once or is it a stay open Applescript ?

If its a stay open Applescript then you could use an on idle Handler.

Code:
on idle
    -- perform periodic tests
    return 1 -- return the number of seconds between the next on idle call
end idle
Regards Mark
Mark FX is offline   0 Reply With Quote
Old Mar 27, 2013, 02:32 PM   #5
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
Pay for the software that is periodically popping up a window asking you to pay for it periodically will make it go away.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Mar 29, 2013, 02:23 PM   #6
DonK KijotE
Thread Starter
macrumors newbie
 
Join Date: Mar 2013
Location: Madrid / Spain
Quote:
Originally Posted by Mark FX View Post
Is your Aplescript run once or is it a stay open Applescript ?

If its a stay open Applescript then you could use an on idle Handler.

Code:
on idle
    -- perform periodic tests
    return 1 -- return the number of seconds between the next on idle call
end idle
Regards Mark
Mark, I understand the "on idle" will start executing if I don't do anything on the system right ?

The thing is I want to perform the routine above explained only when I click a certain button in the software, it's precisely when it's idle that I don't want it to do anything, just wait for me to click and open the referred window...

If I'm not understanding your point correctly let me know

Thanks on beforehand!

I see the user who posted right after you and I don't even know what he's talking about...
DonK KijotE is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Running an AppleScript at a specific time rediffusion Mac Programming 4 Jan 7, 2014 09:09 PM
running videos in background? eclipse01 iOS 7 0 Sep 30, 2013 11:36 AM
How to tell if apps are running in the background chele519 iPhone 17 Sep 26, 2012 08:13 PM
Messages always running in background? stark4 OS X 10.8 Mountain Lion 4 Aug 22, 2012 11:03 AM
My Applescript is running like a dog under ML lloyd709 OS X 10.8 Mountain Lion 0 Jul 26, 2012 10:27 AM

Forum Jump

All times are GMT -5. The time now is 08:24 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC