Created
August 11, 2011 17:17
-
-
Save ePirat/1140222 to your computer and use it in GitHub Desktop.
Crap Script © ePirat
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
-- by MacScripter User Nigel Garvey | |
on switchText(t, r, s) | |
set d to text item delimiters | |
set text item delimiters to s | |
set t to t's text items | |
set text item delimiters to r | |
tell t to set t to item 1 & ({""} & rest) | |
set text item delimiters to d | |
t | |
end switchText | |
-- END | |
-- IsRunning Snipped from http://vgable.com/blog/2009/04/24/how-to-check-if-an-application-is-running-with-applescript/ | |
on ApplicationIsRunning(appName) | |
tell application "System Events" to set appNameIsRunning to exists (processes where name is appName) | |
return appNameIsRunning | |
end ApplicationIsRunning | |
-- END | |
on textualcmd(cmd) | |
try | |
set itunesstring to (do shell script "defaults read com.textualnowplaying itunesstring") | |
on error | |
do shell script "defaults write com.textualnowplaying itunesstring -string 'Now playing %title by %artist [%pos/%length]'" | |
set itunesstring to "Now playing %title by %artist [%pos/%length]" | |
end try | |
try | |
set glue to (do shell script "defaults read com.textualnowplaying glue") | |
on error | |
do shell script "defaults write com.textualnowplaying glue 'and'" | |
set glue to "and" | |
end try | |
try | |
set expyt to (do shell script "defaults read com.textualnowplaying yt") | |
on error | |
do shell script "defaults write com.textualnowplaying yt FALSE" | |
set expyt to false | |
end try | |
try | |
set ignoremute to (do shell script "defaults read com.textualnowplaying ignoremute") | |
on error | |
do shell script "defaults write com.textualnowplaying ignoremute TRUE" | |
set ignoremute to true | |
end try | |
if ApplicationIsRunning("iTunes") then | |
tell application "iTunes" | |
if player state is playing then | |
if (ignoremute as boolean is true) and (sound volume is equal to 0) then | |
set itunes to false | |
else | |
set itunes to true | |
--Calc player pos in min and sec | |
set itunespos to player position | |
set itunesposmin to (itunespos div 60) | |
set itunespossec to (itunespos - (itunesposmin * 60)) | |
if (itunespossec < 10) then set itunespossec to ("0" & itunespossec) as text | |
set itunespos to (itunesposmin & ":" & itunespossec) as text | |
set itunesstring to my switchText(itunesstring, itunespos, "%pos") | |
set dada to current track's artist | |
set itunesstring to my switchText(itunesstring, current track's artist, "%artist") | |
set itunesstring to my switchText(itunesstring, (current track's name), "%title") | |
set itunesstring to my switchText(itunesstring, (current track's album), "%album") | |
set itunesstring to my switchText(itunesstring, (current track's album artist), "%albumartist") | |
set itunesstring to my switchText(itunesstring, (current track's album rating), "%albumrating") | |
set itunesstring to my switchText(itunesstring, (current track's bit rate), "%bitrate") | |
set itunesstring to my switchText(itunesstring, (current track's bpm), "%bpm") | |
set itunesstring to my switchText(itunesstring, (current track's category), "%category") | |
set itunesstring to my switchText(itunesstring, (current track's comment), "%comment") | |
set itunesstring to my switchText(itunesstring, (current track's composer), "%composer") | |
set itunesstring to my switchText(itunesstring, (current track's date added as text), "%added") | |
set itunesstring to my switchText(itunesstring, (current track's description), "%description") | |
set itunesstring to my switchText(itunesstring, (current track's disc count), "%disccount") | |
set itunesstring to my switchText(itunesstring, (current track's disc number), "%discnumber") | |
set itunesstring to my switchText(itunesstring, (current track's disc count), "%disccount") | |
--Calc duration in min and sec | |
--set theduration to current track's duration | |
--set durationmin to (theduration div 60) | |
--set durationsec to (theduration - (durationmin * 60)) | |
--if (durationsec < 10) then set durationsec to ("0" & durationsec) as text | |
--set theduration to (durationmin & ":" & (round (durationsec))) as text | |
set itunesstring to my switchText(itunesstring, (current track's time as text), "%length") | |
set itunesstring to my switchText(itunesstring, (current track's genre), "%genre") | |
set itunesstring to my switchText(itunesstring, (current track's played count), "%playcount") | |
set itunesstring to my switchText(itunesstring, (current track's rating), "%rating") | |
set itunesstring to my switchText(itunesstring, (current track's release date), "%date") | |
set itunesstring to my switchText(itunesstring, (((current track's sample rate) / 1000)), "%samplerate") | |
set itunesstring to my switchText(itunesstring, (current track's episode number), "%episode") | |
set itunesstring to my switchText(itunesstring, (current track's season number), "%season") | |
set itunesstring to my switchText(itunesstring, (current track's release date), "%date") | |
set itunesstring to my switchText(itunesstring, (current track's track count), "%tracklen") | |
set itunesstring to my switchText(itunesstring, (current track's track number), "%tracknr") | |
set itunesstring to my switchText(itunesstring, (current track's track number), "%tracknr") | |
if (current track's video kind as text) is "none" then | |
if current track's podcast as boolean is true then | |
set thekind to "Podcast" | |
else | |
set thekind to "Music" | |
end if | |
else | |
set thekind to current track's video kind | |
end if | |
set itunesstring to my switchText(itunesstring, (thekind), "%kind") | |
return itunesstring as «class utf8» | |
end if | |
else | |
set itunes to false | |
return player state | |
end if | |
end tell | |
end if | |
if ApplicationIsRunning("QuickTime Player") then | |
tell application "QuickTime Player" | |
set countwindow to 1 | |
set test to "" | |
repeat | |
try | |
set test to test & (document countwindow's playing) | |
set countwindow to countwindow + 1 | |
on error | |
exit repeat | |
end try | |
end repeat | |
return test | |
end tell | |
end if | |
end textualcmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment