Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

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.
 
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.
 
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
Thank you maculateConception that second code is what I was looking for but it seems to be rejecting a lot of the code
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.