Skip to content

Instantly share code, notes, and snippets.

@jwmann
Created March 3, 2016 20:13
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 jwmann/7f12fe17264fec943654 to your computer and use it in GitHub Desktop.
Save jwmann/7f12fe17264fec943654 to your computer and use it in GitHub Desktop.
This is an AppleScript to allow the ability to select a song from a VLC playlist and Add the song to your iTunes Library.
global songAdded
global selectedSong
# This variable is used as a boolean to see if a file has been added to iTunes or not
set songAdded to false
# This variable is used to store the alias location of the song to be deleted / added
set selectedSong to false
getSong()
addSong(selectedSong)
finishUp()
on getSong()
# Reveal selected song from the VLC playlist in the Finder
tell application "VLC"
activate
try
tell application "System Events" to keystroke "r" using {shift down, command down}
end try
end tell
# Save the selected song
if is_active("Finder", true) is true then
tell application "Finder"
set selectedSong to (get selection as alias)
end tell
end if
end getSong
# Add Song to iTunes Library
on addSong(selectedSong)
# Bail out if there's no saved selected song
if selectedSong is not false then
tell application "iTunes"
launch
end tell
if is_running("iTunes", true) is true then
try
tell application "iTunes"
add selectedSong to playlist "Music" of source "Library"
set songAdded to true
end tell
end try
end if
end if
end addSong
on finishUp()
tell application "Finder" to close window 1
tell application "VLC" to activate
end finishUp
# Utility functions
on is_running(appName, waitBoolean)
tell application "System Events"
set appRunning to (name of processes) contains appName
if waitBoolean is true then
# Wait for the App to start running
set wait to 0
repeat until appRunning is true or wait is greater than 8
set appRunning to (name of processes) contains appName
set wait to wait + 0.1
delay 0.1
end repeat
end if
return appRunning
end tell
end is_running
on is_active(appName, waitBoolean)
tell application "System Events"
set activeApp to (name of first application process whose frontmost is true) contains appName
if waitBoolean is true then
# Wait for the App to become active
set wait to 0
repeat until activeApp is true or wait is greater than 2
set activeApp to (name of first application process whose frontmost is true) contains appName
set wait to wait + 0.1
delay 0.1
end repeat
end if
return activeApp
end tell
end is_active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment