Now Playing脚本更新 添加判断iTunes是否正在运行功能

现在可以判断iTunes是否运行了,当iTunes未运行时会弹出对话框询问用户是否打开iTunes

Safari版

1
tell application "System Events" to set isRunning to exists (processes where name is "iTunes")

if not isRunning then

	display dialog "是否打开iTunes?"

	tell application "iTunes" to activate

	repeat until isRunning

		tell application "System Events" to set isRunning to exists (processes where name is "iTunes")

	end repeat

end if

tell application "iTunes"
	play
	set trackName to name of current track
	set artistName to artist of current track
	set albumname to album of current track
	set timename to time of current track
end tell

on replaceChars(aString, charToReplace, newChar)
	set {TID, text item delimiters} to {text item delimiters, charToReplace}
	set aString to text items of aString
	set text item delimiters to newChar
	set aString to aString as text
	set text item delimiters to TID
	return aString
end replaceChars

set outputUrl to replaceChars("http://music.wayshine.us/nowplaying.php?album=" & albumname & "&artist=" & artistName & "&title=" & trackName & "&length=" & timename & "&from=233" & "&c=0", " ", "%20")


tell application "Safari"
	activate
	try
		tell window 1 to set current tab to make new tab with properties {URL:outputUrl & "&s=0"}
	on error
		open location outputUrl & "&s=0"
	end try
end tell

set the clipboard to outputUrl & "&s=3"

Chrome版

1
tell application "System Events" to set isRunning to exists (processes where name is "iTunes")

if not isRunning then

	display dialog "是否打开iTunes?"

	tell application "iTunes" to activate

	repeat until isRunning

		tell application "System Events" to set isRunning to exists (processes where name is "iTunes")

	end repeat

end if

tell application "iTunes"
	play
	set trackName to name of current track
	set artistName to artist of current track
	set albumname to album of current track
	set timename to time of current track
end tell

on replaceChars(aString, charToReplace, newChar)
	set {TID, text item delimiters} to {text item delimiters, charToReplace}
	set aString to text items of aString
	set text item delimiters to newChar
	set aString to aString as text
	set text item delimiters to TID
	return aString
end replaceChars

set outputUrl to replaceChars("http://music.wayshine.us/nowplaying.php?album=" & albumname & "&artist=" & artistName & "&title=" & trackName & "&length=" & timename & "&from=233" & "&c=0", " ", "%20")


tell application "Google Chrome"
	activate
	set theUrl to outputUrl & "&s=0"

	if (count every window) = 0 then
		make new window
	end if

	set found to false
	set theTabIndex to -1
	repeat with theWindow in every window
		set theTabIndex to 0
		repeat with theTab in every tab of theWindow
			set theTabIndex to theTabIndex + 1
			if theTab's URL = theUrl then
				set found to true
				exit repeat
			end if
		end repeat

		if found then
			exit repeat
		end if
	end repeat

	if found then
		tell theTab to reload
		set theWindow's active tab index to theTabIndex
		set index of theWindow to 1
	else
		tell window 1 to make new tab with properties {URL:theUrl}
	end if
end tell

set the clipboard to outputUrl & "&s=3"