Dear all,
i try to sync my current track in iTunes with an oH2-Item:
set itunes_state to false
if is_app_running("iTunes") then
tell application "iTunes" to set itunes_state to (player state as text)
end if
(* Whatever other music applications you use *)
if itunes_state is equal to "playing" then
tell application "iTunes"
set track_name to name of current track
set artist_name to artist of current track
return artist_name & " - " & track_name
do shell script curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "Test" "http://192.XXX.XXX.XXX:8080/rest/items/00_CurrentSongTitle/state"
end tell
else
return "Nothing playing :("
do shell script curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "Test" "http://192.XXX.XXX.XXX:8080/rest/items/00_CurrentSongTitle/state"
end if
on is_app_running(app_name)
tell application "System Events" to (name of processes) contains app_name
end is_app_running
curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "Test" "http://192.168.178.53:8080/rest/items/00_CurrentSongTitle/state"
works from Terminal, but not from AppleScript - maybe there must be a speciel formatting of the command?
I try even a shell-script:
#!/bin/bash
NOW_PLAYING=$(osascript <<EOF
if is_app_running("iTunes") then
tell application "iTunes" to set itunes_state to (player state as text)
end if
(* Whatever other music applications you use *)
if itunes_state is equal to "playing" then
tell application "iTunes"
set track_name to name of current track
set artist_name to artist of current track
return artist_name & " - " & track_name
end tell
else
return "Nothing playing :("
end if
on is_app_running(app_name)
tell application "System Events" to (name of processes) contains app_name
end is_app_running
EOF)
echo $NOW_PLAYING
curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d $NOW_PLAYING "http://192.168.178.53:8080/rest/items/00_CurrentSongTitle/state"
here i got this errors:
nowplaying.sh: line 23: unexpected EOF while looking for matching `"'
nowplaying.sh: line 24: syntax error: unexpected end of file
i think its a problem with the format of the curl-string?