Skip to content

Instantly share code, notes, and snippets.

@basuke
Created October 14, 2014 18:56
Show Gist options
  • Save basuke/a9f16df53109f9691004 to your computer and use it in GitHub Desktop.
Save basuke/a9f16df53109f9691004 to your computer and use it in GitHub Desktop.
AlfredTweet patch. track informations should not be encoded to utf-8 at this point. Workflow seems to handle encoding correctly.
/**
* Description
* Accepts a player name as an argument and reads the values
* of the track name and artist for the currently playing track
* of that player
*
* @param $player - name of the player to read data from
* @return array - array of track name and artist for that player
*/
function get_tracks( $players )
{
$tracks = array();
foreach( $players as $player ):
$track = `osascript -e 'tell application "$player" to return name of current track'`;
$artist = `osascript -e 'tell application "$player" to return artist of current track'`;
$album = `osascript -e 'tell application "$player" to return album of current track'`;
$track = str_replace("\n", "", $track);
$artist = str_replace("\n", "", $artist);
$album = str_replace("\n", "", $album);
array_push( $tracks,
array(
'track' => $track,
'artist' => $artist,
'album' => $album,
'player' => $player
)
);
endforeach;
return $tracks;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment