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

Tpeng_tcm

macrumors newbie
Original poster
Jun 29, 2017
2
0
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.
 

casperes1996

macrumors 68040
Jan 26, 2014
3,956
1,903
Horsens, Denmark
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.

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.
 

0002378

Suspended
May 28, 2017
676
631
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
}
 
  • Like
Reactions: Tpeng_tcm

Tpeng_tcm

macrumors newbie
Original poster
Jun 29, 2017
2
0
Thank you maculateConception that second code is what I was looking for but it seems to be rejecting a lot of the code
 

0002378

Suspended
May 28, 2017
676
631
Thank you maculateConception that second code is what I was looking for but it seems to be rejecting a lot of the code
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