Nevermind, I found a solution and I tested that gist. It was needed just a little fix with converting float variable (AppleScript returns "float" with comma instead of dot, so I just replaced "," to "." and converted to float). This is fixed script, just add it to /powerline/segments/common/players.py
.
class iTunesPlayerSegment(PlayerSegment):
def get_player_status(self, pl):
status_delimiter = '-~`/='
ascript = '''
tell application "System Events"
set process_list to (name of every process)
end tell
if process_list contains "iTunes" then
tell application "iTunes"
if player state is playing or player state is paused then
set t_title to name of current track
set t_artist to artist of current track
set t_album to album of current track
set t_duration to duration of current track
set t_elapsed to player position
set t_state to player state
return t_title & "{0}" & t_artist & "{0}" & t_album & "{0}" & t_elapsed & "{0}" & t_duration & "{0}" & t_state
end if
end tell
end if
'''.format(status_delimiter)
now_playing = asrun(pl, ascript)
if not now_playing:
return
now_playing = now_playing.split(status_delimiter)
if len(now_playing) != 6:
return
now_playing[4] = now_playing[4].replace(',', '.')
title, artist = now_playing[0], now_playing[1]
title = title[0:25] + "…" if len(title) > 25 else title
artist = artist[0:15] + "…" if len(artist) > 15 else artist
state = _convert_state(now_playing[5])
total = _convert_seconds(now_playing[4])
elapsed = _convert_seconds(float(now_playing[4]) - float(now_playing[4]))
return {
'title': title,
'artist': now_playing[1],
'album': now_playing[2],
'total': total,
'elapsed': elapsed,
'state': state
}
itunes = with_docstring(iTunesPlayerSegment(),
('''Return iTunes now playing information.
Requires ``osascript``.
{0}
''').format(_common_args.format('itunes')))
And it looks that . I hope it will help someone 😄
Somehow I still can't get itunes now playing to show up in my tmux statusline.
powerline/segments/common/players.py
.{
"segments": {
"right": [
{
"function": "powerline.segments.common.players.itunes",
"name": "player"
},
...
],
...
}
}
powerline-lint
shows no errors.powerline-config tmux setup
(with log_level=DEBUG
) shows nothing related to the player.I have made other changes to my tmux theme and see them reflected in my statusbar, but still no itunes now playing.
I tested the applescript from the above script to make sure it returns the desired string, which seems to be ok.
Am I missing something in my powerline configuration?
@eliath Did you restart the powerline daemon? “I … see them reflected in my statusbar” is not relevant: actually powerline is supposed to reload its configuration after changes and this sometimes work. But it won’t reload any python code.
Yep, that was it. After reloading my tmux config and restarting the daemon, everything works as expected. Thanks!
This was merged some time ago from #1732.
Most helpful comment
Nevermind, I found a solution and I tested that gist. It was needed just a little fix with converting float variable (AppleScript returns "float" with comma instead of dot, so I just replaced "," to "." and converted to float). This is fixed script, just add it to
/powerline/segments/common/players.py
.And it looks that . I hope it will help someone 😄