Running  applescript in background (as a standalone app or iTunes script)

Hiya,
I'm working on making an Apple script that syncs my currently playing track with Twitter, Facebook, and Last.fm. I have the syncing portion worked out, but the method in which the program receives information is not ideal.
I was wondering if there exist a set of commands that allows my program to work in the backhround, monitoring itunes for track-changes. Once a track changes, the syncing process will begin. Once the process ends, the program will once again become a background processes. This also beckons the question: is there a command for my program to launch when iTunes launches. I know Last.FM's official client has an option that allows the program to launch when iTunes launch. I would like to know if that's easy to implement.
Ideally, if anyone can point me to a page/book for tutorials on how to futz around with iTunes commands and background processes, I would be greatful!
Thanks!

The background element of your request is fairly straightforward - use an 'idle' handler.
In this case you want your idle handler to periodically check the state of iTunes and perform whatever actions you like once you know it's open.
The other element - having your script open when iTunes opens, is not so easy. iTunes doesn't have the option to run a script or perform any action when it's opened. Therefore there's no easy way to achieve this - at least not via AppleScript. The typical way of doing it is to write a daemon process that sits in the background, but this isn't easy in AppleScript, or write a plug-in (which also isn't possible in AppleScript).
As a result your best option may be to have an AppleScript app that's always running (e.g. launched at login) which sits around checking for iTunes, and kicking in once it detects iTunes has launched.
Something like:
-- variable to keep track of iTunes state last time we checked:
global iTunesWasRunning
on run
  set iTunesWasRunning to false
end run
on idle
  if application "iTunes" is running then
    -- it's running now, was it running before?
    if iTunesWasRunning then
      -- code here for checking track changes
    else
      -- it's just been launched, so do whatever you need on app launch
    end if
  end if
  -- remember the current app state for the next iteration
  set iTunesWasRunning to (application "iTunes" is running)
  -- check again in 10 seconds time
  return 10
end idle
Now you have three places you can run code - iTunes is still running, iTunes has just been launched, and itunes isn't running at all. From here you should be able to insert the relevant code for what you're trying to achieve.

Similar Messages

  • Kill QuickTime running in the background from my iphone app?

    Is it possible to send a kill or stop or pause quicktime command from within an iphone app? I would like to add a button to kill music playing in the background from streaming radio in safari/quicktime so user does not have to launch safari to stop the background music. Example: if I have a painting app the user can press a button in the app that will stop the music. Thanks.

    If you're talking about closing running apps, they changed it up a bit from iOS6. Now you just double click the home button to bring up the running apps, side scroll to the app you want to close, then just swipe up.
    = L.I.

  • If Safari or internet apps are running in the "background..."

    Are they still going using data? I'm a new member on a 2GB a month plan. Most of the time I'm on wifi, but not always. I've been being careful to turn them off if I'm not on wifi, but how careful do I have to be? I don't really know much about this.
    Btw, what is a quick way to turn my apps off? The double click method on the circle and then hold a button until the minus button comes up and turn them off that way or is there a quicker way?

    Very few apps run in the background - mainly music playing apps and GPS apps.  Double-clicking the Home button gives you a list of previously used apps, not (as so many people believe) "running" apps.  You can delete the apps from the list if you wish, but it will make no difference to energy usage (unless they actually are running, as in the categories above. You should know if you are using GPS or if you can hear music).

  • HT4528 I have an IPhone 4S--How do I see if apps are running in the background and should they be deleted?

    I have an IPhone 4S.  How do I see if there are any apps open in the background and if so, should they be deleted to save energy?
    Thanks

    Very few apps run in the background - mainly music playing apps and GPS apps.  Double-clicking the Home button gives you a list of previously used apps, not (as so many people believe) "running" apps.  You can delete the apps from the list if you wish, but it will make no difference to energy usage (unless they actually are running, as in the categories above. You should know if you are using GPS or if you can hear music).

  • Please tell me how to shut down apps running in the background on my iPad.  I downloaded ios7, and now when I hold my finger on them they don't have the plus sign

    Please tell me how to shut down apps running in the background with ios7

    Shut down apps
    1. Double tap the home button to bring up the multi-tasking view
    2. Swipe the app's windows upwards to close
    3. The app will fly off the screen

  • How to you stop the health app running in the background?

    How to you stop the new Health App from running in the background? Its its always running collecting data on how many steps I have taken and how far I have walked.. I walked 12000 steps and travelled 4.1km DRIVING my kids to school this morning according to the app.

    I never intend to use the health app because I do not need an app on my phone to help me live a healthy lifestyle.  Therefore I find it intrusive there is no way to stop it from tracking my steps or whatever else it may be doing.  I found a way to force the app to crash and maybe this will stop it from running in the background.  Open the app, tap "Health Data" at the bottom of the screen, tap "Fitness" then "Steps" and tap "Add Data" type in a huge number - a very huge number with 30 or more characters, you can even add more than 1 decimal point.  Repeat this for "walking + Running Distance".  From this point forward the app will crash when you try to look at the data.  Maye this prevents it from recording new data, I'm not sure but I really like the fact the app crashes.  Hopefully Apple will add a feature to allow us to turn off data collection altogether or even better, allow us to delete this app.

  • Running threads in background

    I'm developing something like a Task Scheduler for my
    application. The user will select as task and schedule
    it to run in the background at a given time. When the
    task has finished running, an email will be sent to the
    user with the results.
    So I need a Task Scheduler. My scheduler will run as a
    background process within the app server and poll the
    database for new tasks to be run. The polling will
    happen every 1 minute or so. It will pick up all the
    new tasks that are due to be run, and then start 1
    separate thread for each task. When the task is done,
    the task thread will email the results to the user.
    My question is - how do I run the scheduler thread (the
    one that polls the database) in the background? The
    thread can sleep for 1 minute and then poll again.
    The other question is - am I allowed to run Threads in
    an app server environment (someone told me I'm not
    allowed to do that, as per the J2EE Standard).
    I'm looking for a J2EE-compliant solution - one that
    can be easily shifted to any app server other than
    WebLogic.
    Thanks a lot in advance.
    Manish Jethani

    You will want to create a startup class that schedules a trigger to run every
    minute.
    Mike
    "Manish Jethani" <[email protected]> wrote:
    >
    I'm developing something like a Task Scheduler for my
    application. The user will select as task and schedule
    it to run in the background at a given time. When the
    task has finished running, an email will be sent to the
    user with the results.
    So I need a Task Scheduler. My scheduler will run as a
    background process within the app server and poll the
    database for new tasks to be run. The polling will
    happen every 1 minute or so. It will pick up all the
    new tasks that are due to be run, and then start 1
    separate thread for each task. When the task is done,
    the task thread will email the results to the user.
    My question is - how do I run the scheduler thread (the
    one that polls the database) in the background? The
    thread can sleep for 1 minute and then poll again.
    The other question is - am I allowed to run Threads in
    an app server environment (someone told me I'm not
    allowed to do that, as per the J2EE Standard).
    I'm looking for a J2EE-compliant solution - one that
    can be easily shifted to any app server other than
    WebLogic.
    Thanks a lot in advance.
    Manish Jethani

  • ICal failing to run applescripts: The 'Open' button does not change to 'Run', and the script file is opened but not executed on alert.

    iCal failing to run applescripts: The 'Open' button does not change to 'Run', and the script file is opened but not executed.

    Calendar (not called iCal anymore) does not include that capability any longer, apparently.  What you have to do now is go to Automator and create a Calendar Alert action.  You can add a Run AppleScript object to the action and paste in your script there, then when you save it, it will become available as a choice in the alert menu in Calendar.

  • Run VLC as background through Applescript, and more

    Qualifiers:
    VLC version 0.9.10
    OSX 10.4.11
    Applescript 2.1
    I am trying to set up an Applescript to run VLC in stream capture mode in the background.   I can get it to work with:
    do shell script "[path to bundle in VLC app] [stream URL] --sout=file/raw:[path to saved file].raw &> /dev/null 2>&1& echo $!"
    This opens up a VLC application window, captures, and all is fine.  Before I routed all the output at the end of the command it would capture the stream but the script would remain frozen until I quit the VLC application, hence the stuff at the end.  My script needs to keep running actively because it includes a component to periodically check the capture is still taking place (my Internet connection can be dodgy with wi-fi interference from neighbors) by monitoring the modification date of the capture file, so I have to route the output to null so the script doesn't hang.  I tried running it with just the background & and it still hung.  Oh, I am capturing the PID so I can include a kill command to stop the process later.
    I tried doing something similar with
    do script with command etc. -- (modification of end of command line so it finishes after ".raw")
    in Terminal and it worked too, though it opened up a couple of Terminal windows which had to stay open all the time and when I wanted to stop the capture I had to close the VLC Terminal window.
    Now the real issue.  I want to have a second copy of VLC running for other use while the first is doing things quietly.  I know it can be done.  Before writing my Applescript I used to have one copy of VLC in GUI mode capturing a stream and a second copy of the app in GUI for playing other media, both running happily side by side.  It also worked when I ran it from an Applescript with the first VLC channeling through Terminal output. Now when I have the first copy running via Applescript I can open the second copy but when I try to play a file VLC just plays the whole thing back in a few seconds with no output.  It seems the output channeling from the first command line invocation of VLC is also influencing the second application (?? !)  Although I have renamed the application I didn't start messing with things in the app package itself so maybe I also need to change some identifiers in plist settings or bundle names so it really is accepted as a completely different app?
    I know this is a mix of archaic OSX technologies, both Unix and Applescript, and maybe something non-Apple and VLC-specific but I spent an hour or two doing web searches for tips, and a lot of experimentation with various combinations myself and didn't get far.  I am not sure if I have explored all the possibilities with the shell command, or if I can do something to change my second VLC application so it truly stands alone, or this just won't work, or...?
    Oh, just in case somebody suggests it, using an "open" in a shell script does not have a -n flag under Tiger OS, so I can't start a new instance of the old VLC that way (and it may suffer the same problem).

    I discovered that even when I quit my script and tried running VLC normally after that it still wasn't playing things normally although repeated runs of the script go things running in the background fine.  I trashed VLC's preferences and things played normally.  I really wish I know how to get a second copy of VLC to run in complete isolation of the first, including separate preferences, since it is a nuisance to have to trash preferences to switch between uses of VLC.

  • How can I delete the apps that run in the background in iOS 7

    HOw can I delete the apps running I the background in the new Ios7. Earlier all that I had to do was to press continuously and then could delete when the   Mark would appear. now I am unable to do it.
    AAlso, I am unable to save a photograph as a wall paper.

    Thanks so much. This solved my problem.
    Can you tell me how to save a photograph as a wall paper on the new IOS 7
    Thanks

  • Looking for a drum loop app that will run in the background. What are you using?

    Looking for a drum loop app that will run in the background. Suggestions? What are you using? I tried Loopseque and I like it, but I can't make it run once I switch apps. Help please.

        That's definitely strange, kzmidge. I want a working phone in your hands though. I noticed you mentioned you received the suggestion to complete a reset. Did you already do that? Is it working again? Are you receiving an error message?
    If you hesitated a little longer to complete the reset, you can try to place your phone into Safe Mode http://vz.to/rxg0ii and see if you can access mobile sites from your browser. This mode will stop 3rd party applications from running, so you won't be able to use the apps you mentioned but we may be able to narrow down the trouble in Safe Mode. If the mobile sites work, that means the trouble may be in a recently downloaded application and you may be able to avoid the reset my uninstalling some of your more recently installed applications. If it's still giving you trouble, the reset http://vz.to/18wzOCi is the next best step.
    JenniferH_VZW
    Follow us on Twitter www.twitter.com/vzwsupport

  • How do I turn off apps running in the background on iOS7?

    I just updated my iPhone 5 to iOS7.  How do I turn off apps running in the background? Double tapping the home button and turning each one off doesn't work on the updated iOS.

    Double click the Home button and "slide" the open apps 'UP" with your finger, they will disappear.

  • How do i turn off apps running in the background with the new upgrade?

    how do i turn off apps running in the background with the new upgrade?

    They changed it a bit, but you can still close apps. Double click the Home button to pull up the currently running apps. Side scroll over to the app you want to close, then swipe up on the app *window* (not the icon at the bottom).
    = L.I.

  • How do i turn off apps running in the background

    How do I stop apps from running in the background?

    Do you mean u have no idea what apps they are? You could try Activity Monitor, but be careful there that you won't close / quit apps which might be needed by your system..
    If you have some apps which startup in the background when logging in, you can find it in system preferences -> Users & Groups, select your user and then select the tab Login Items.

  • Is there a way to keep apps from running in the background?

    I just updated to an Iphone 6, with the latest version of IOS.  It's a great product, but for me there is one annoyance.  There are times when my memory gets low.  I find out that it's the apps that are running in the background.  I personally don't use this.  All it does is hog memory.  Then, to close the apps, you have to close each one individually.  I forgot how many apps I have open, I'm of the mindset that when I close the app, that it's "really" closed, not still running in the background.  It would be nice if there was a way to disable this function.  It doesn't seem to serve a purpose for me in the way I use the Iphone.  I just "cleaned up my list of "behind the scenes apps" and I had about 20.  It gets frustrating to have to go to each one to close it.  Any comments or suggestions?

    Some things that might help:
    1. Only the most recently used apps actually occupy memory (used to be the most recent 4, but may have changed in the latest iPhones). After 4 (or so), IOS writes them out of active memory, as it does for even the latest 4 if there's no activity for a long time. So the business of closing all the open apps, apart from the most recent ones doesn't make a difference. Tis article has a good explanation:
    http://www.speirs.org/blog/2012/1/2/misconceptions-about-ios-multitasking.html
    2. There are settings about background app activity that might help:
    - Settings, General, Background App Refresh controls which apps can update their data in the background
    - Settings, Notifications controls which apps can tell you things, which they have to wake up to do.
    - Settings, Privacy, Location Services controls which apps monitor your location - another activity that uses resources
    Hope some of that helps

Maybe you are looking for