Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6553615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:36:11+00:00 2026-05-25T12:36:11+00:00

I have an Applescript I use in conjunction with Alfred that plays or pauses

  • 0

I have an Applescript I use in conjunction with Alfred that plays or pauses the current track in iTunes or Rdio, depending on which I have open. In my script Rdio takes precedence because I always have iTunes open and only open Rdio when I need it for a specific purpose.

Often, when a track is playing in iTunes and I hit my global shortcut to run this script it takes up to 15 seconds to stop the track. I wanted to share the script here and see if there might be a glaring issue, or if there is a much simpler, more efficient way to handle it.

I appreciate any help I can get!

tell application "System Events"
    if (name of processes) contains "iTunes" then
        set iTunesRunning to true
    else
        set iTunesRunning to false
    end if
    if (name of processes) contains "Rdio" then
        set RdioRunning to true
    else
        set RdioRunning to false
    end if
end tell

if RdioRunning then
    tell application "Rdio"
        if player state is paused or player state is stopped then
            play
        else if player state is playing then
            pause
        end if
    end tell
else if iTunesRunning then
    tell application "iTunes"
        if player state is paused or player state is stopped then
            play
        else if player state is playing then
            pause
        end if
    end tell
end if
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:36:11+00:00Added an answer on May 25, 2026 at 12:36 pm

    It’s difficult to track down such issues. In general your script looks fine. Here’s some ideas that may help with your problem though.

    In general applescripts are interpreted at run-time which means that every time you run your script the byte-code has to be changed into machine language code by another program (applescript runner)… this is normally not a problem but in your case maybe it’s causing some slowness. So the idea is to write your script so that doesn’t need to happen. We can do that by saving the script as an applescript application because applications are saved in the machine language form and thus do not require another program to execute the code. In addition we can take advantage that the commands for both applications are identical, so we can use a “using terms from” block. In your code you query system events for the “name of processes” twice, so the last optimization we can make is to only do that once.

    So try this and see if it helps. I’m not certain it will but it’s worth a try. Remember to save it as an application.

        tell application "System Events" to set pNames to name of application processes
    
        if "Rdio" is in pNames then
            set appName to "Rdio"
        else if "iTunes" is in pNames then
            set appName to "iTunes"
        else
            return
        end if
    
        using terms from application "iTunes"
            tell application appName
                if player state is paused or player state is stopped then
                    play
                else if player state is playing then
                    pause
                end if
            end tell
        end using terms from
    

    EDIT: If the above code doesn’t work then try this. As mentioned, try it as an application and see if it helps. The same principles apply… one less query of system events and saving as an application to prevent needing to interpret the code.

    tell application "System Events" to set pNames to name of application processes
    
    if "Rdio" is in pNames then
        tell application "Rdio"
            if player state is paused or player state is stopped then
                play
            else if player state is playing then
                pause
            end if
        end tell
    else if "iTunes" is in pNames then
        tell application "iTunes"
            if player state is paused or player state is stopped then
                play
            else if player state is playing then
                pause
            end if
        end tell
    end if
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an AppleScript script that I use to display iTunes track information on
I have a computer (Mac) that is authorized to play music through iTunes which
I have an AppleScript program which creates XML tags and elements within an Adobe
I have written an AppleScript which when supplied with a Windows network link, will
So I have this program that I really like, and it doesn't support Applescript.
I have to write an Applescript to automount a folder depending on the user.
I'm just starting with applescript in xcode and currently have an app that asks
Using AppleScript, Can I open a URL in the CURRENT Safari window (i.e. without
I have some AppleScript code that I'm executing with osascript . This is part
I have such an AppleScript: tell application Firefox activate set the bounds of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.