Created
April 20, 2018 15:33
-
-
Save td512/06e7dac669ad8c7afad839d96606a232 to your computer and use it in GitHub Desktop.
Updated Spotify AppleScript for Textual
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Copyright © 2018, Theo Morra. All rights reserved. | |
https://theom.nz/ | |
Redistribution and use in source and binary forms, with or without modification, are | |
permitted provided that the following conditions are met: | |
Redistributions of source code must retain the above copyright notice, this list of | |
conditions and the following disclaimer. | |
Redistributions in binary form must reproduce the above copyright notice, this list | |
of conditions and the following disclaimer in the documentation and/or other materials | |
provided with the distribution. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
*) | |
on textualcmd(inputData, destinationChannel) | |
if destinationChannel is equal to "" then | |
return "/debug Invalid destination channel" | |
end if | |
if appIsNotRunning("Spotify") then | |
return "/debug You are not running Spotify" | |
end if | |
set nowPlaying to "I'm not currently playing anything." | |
if not appIsNotRunning("Spotify") then | |
tell application "Spotify" | |
set playtime to (do shell script "date -r " & (round player position as integer rounding as taught in school) & " +%M:%S") --- because it's easier to use printf | |
set track_time to (round ((duration of current track) / 1000) as integer rounding as taught in school) --- because AppleScript won't let me divide in one go | |
set track_duration to (do shell script "date -r " & track_time & " +%M:%S") | |
if player state is playing then set nowPlaying to "/sme " & destinationChannel & " ♫ Currently playing: " & artist of current track & " - " & name of current track & " from the album " & album of current track & " on Spotify. Play time: " & playtime & " / " & track_duration & " ♫" | |
end tell | |
end if | |
return nowPlaying | |
if spotifyStatus is "paused" then | |
set returnString to ("/sme " & destinationChannel & " has Spotify paused.") | |
end if | |
if spotifyStatus is "stopped" then | |
set returnString to ("/sme " & destinationChannel & " has Spotify stopped.") | |
end if | |
return returnString | |
end textualcmd | |
on isRunning(mediaPlayer) | |
tell application "System Events" | |
tell application "System Events" to return exists (processes where name is mediaPlayer) | |
end tell | |
end isRunning | |
on appIsNotRunning(appName) | |
tell application "System Events" to (name of processes) does not contain appName | |
end appIsNotRunning |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment