Is there a way to create an applescript that closes iTunes upon it opening

Discussion in 'Mac Apps and Mac App Store' started by Tpeng_tcm, Jun 29, 2017.

  1. Tpeng_tcm macrumors newbie

    Joined:
    Jun 29, 2017
    #1
    My earbuds are acting up and they keep on playing music when every they want to. I have used applescript before but is only to open apps not close them.
     
  2. casperes1996 macrumors 65816

    casperes1996

    Joined:
    Jan 26, 2014
    Location:
    Horsens, Denmark
    #2

    I'm a bit confused. Is the problem that your earbuds automatically start iTunes? If you mean iTunes opens with the system, just disable that.
     
  3. maculateConception macrumors 6502

    maculateConception

    Joined:
    May 28, 2017
    Location:
    Die Bundesstaat Kalifornien
    #3
    This is how you quit iTunes:

    Code:
    tell application "iTunes"
        quit
    end tell
    I'm not sure if you want some sort of background process (agent) that is always running, keeping an eye out to see if iTunes is running. And, whenever it opens, to close it, to prevent if from ever running If so, then, you need to run your AppleScript in some sort of loop. Here is some pseudocode to do so:

    Code:
    while (true) {    // always run
    
    tell application "iTunes"
        quit
    end tell
    
    sleep 10 seconds   // sleep so that you don't hog the CPU for no reason
    }
     
  4. Tpeng_tcm thread starter macrumors newbie

    Joined:
    Jun 29, 2017
    #4
    Thank you maculateConception that second code is what I was looking for but it seems to be rejecting a lot of the code
     
  5. maculateConception macrumors 6502

    maculateConception

    Joined:
    May 28, 2017
    Location:
    Die Bundesstaat Kalifornien
    #5
    Oh, I'm sorry, the second block of code was written in pseudocode (i.e. it shows you what you want to do logically, but it may not be syntactically correct). Sorry for confusing you.

    Here's syntactically correct Applescript for the second block of code. This should work as is:

    Code:
    repeat
    
    tell application "iTunes"
       quit
    end tell
    
    // Sleeps (waits) 10 seconds. Adjust this time interval (in seconds) to what works for you. 
    // This is how often you want your script to "wake up" and check for iTunes running
    delay 10
    
    end repeat
     

Share This Page