Skip to content

Instantly share code, notes, and snippets.

@Kalli
Created December 7, 2012 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kalli/4234836 to your computer and use it in GitHub Desktop.
Save Kalli/4234836 to your computer and use it in GitHub Desktop.
iTunes Set BPM
(*
Set the bpm value of the current iTunes track to the bpm value of the counter http://www.all8.com/tools/bpm.htm or a selected number
written by Karl Tryggvason www.karltryggvason.com / @karltryggvason
*)
if appIsRunning("Google Chrome") then
tell application "Google Chrome"
if (get URL of active tab of first window) is equal to "http://www.all8.com/tools/bpm.htm" then
tell window 1
tell active tab
set the_bpm to execute javascript ("document.getElementsByName('T_WHOLE')[0].value")
end tell
end tell
else
set the_bpm to ""
end if
end tell
else
set the_bpm to ""
end if
tell application "iTunes"
activate
set this_track to ""
if player state is playing then set this_track to current track
if this_track is "" then
display dialog "No track is playing..." buttons {"Cancel"} default button 1 with icon 2 giving up after 15
else
try
with timeout of 30 seconds
set display_string to "Please enter bpm"
if the_bpm = "" then
set the_bpm to 120
repeat
set response to display dialog display_string default answer the_bpm
try
set the_bpm to (text returned of response) as number
exit repeat
on error errstr
set displayString to errstr & return & "Please try again."
set the_bpm to text returned of response
end try
end repeat
end if
end timeout
tell this_track
set bpm to the_bpm
end tell
on error
return
end try
end if
end tell
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment