-
Notifications
You must be signed in to change notification settings - Fork 10
/
apps-and-itunes.coffee.optional
224 lines (184 loc) · 8.02 KB
/
apps-and-itunes.coffee.optional
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
options =
focus: false
desktop: true
commands =
isitunesrunning: "osascript -e 'if application \"iTunes\" is running then return true'"
isspotifyrunning: "osascript -e 'if application \"Spotify\" is running then return true'"
isitunesplaying: "osascript -e 'if application \"iTunes\" is running then tell application \"iTunes\" to if player state is playing then return true'"
isspotifyplaying: "osascript -e 'if application \"Spotify\" is running then tell application \"Spotify\" to if player state is playing then return true'"
itunes: "osascript -e 'if application \"iTunes\" is running then tell application \"iTunes\" to if player state is playing then artist of current track & \" - \" & name of current track'"
spotify: "osascript -e 'if application \"Spotify\" is running then tell application \"Spotify\" to artist of current track & \" - \" & name of current track '"
activedesk: "echo $(/usr/local/bin/chunkc tiling::query -d id)"
command: "echo " +
"$(#{ commands.activedesk }):::" +
"$(#{ commands.isitunesrunning}):::" +
"$(#{ commands.isspotifyrunning}):::" +
"$(#{ commands.isitunesplaying}):::" +
"$(#{ commands.isspotifyplaying}):::" +
"$(#{ commands.itunes}):::" +
"$(#{ commands.spotify})"
refreshFrequency: '10s'
getIcon: ( processName ) -> # No spaces, no numbers in the app name.
icon = switch
#Apple Apps
when processName == "?" then "fab fa-apple"
when processName == "Finder" then "far fa-window-restore"
when processName == "Preview" then "fas fa-eye-dropper"
when processName == "Safari" then "fa fa-compass"
when processName == "iTunes" then "fab fa-itunes-note"
when processName == "Mail" then "far fa-envelope"
when processName == "ActivityMonitor" then "far fa-window-close"
#Microsoft Office
when processName == "MicrosoftWord" then "fas fa-file-word"
when processName == "MicrosoftPowerPoint" then "fas fa-file-powerpoint"
when processName == "MicrosoftExcel" then "fas fa-file-excel"
when processName == "MicrosoftOutlook" then "fas fa-file-outlook"
#Writing / Programming
when processName == "Atom" then "far fa-code"
when processName == "SublimeText" then "far fa-code"
when processName == "Hyper" then "far fa-terminal"
when processName == "iTerm" then "far fa-terminal"
when processName == "Terminal" then "far fa-terminal"
#Music
when processName == "Spotify" then "fab fa-spotify"
#Messaging
when processName == "WhatsApp" then "fab fa-whatsapp"
when processName == "Airmail" then "far fa-envelope"
when processName == "Spark" then "far fa-envelope"
else "far fa-window-maximize"
if icon == "far fa-window-maximize"
if processName.search("Win") > -1 || processName.search("prl") > -1 #parallels apps
icon = "fab fa-windows"
return icon
render: ( ) ->
"""
<div class="container">
<div class="widg tray-button pinned red" id="home">
<div class="icon-container" id="home-icon-container">
<span id="active-desktop"></span>
</div>
</div>
<div class="tray hidden" id="home-tray">
<div class="widg launcher" id="open /Applications/Safari.app">
<div class="icon-container" id="browser-icon-container">
<i class="icon far fa-compass"></i>
<span class="alt-text">BROWSER</span>
</div>
</div>
<div class="widg launcher" id="open '/Applications/Airmail 3.app'">
<div class="icon-container" id="mail-icon-container">
<i class="icon far fa-envelope"></i>
<span class="alt-text">MAIL</span>
</div>
</div>
<div class="widg launcher" id="open /Applications/WhatsApp.app">
<div class="icon-container" id="messages-icon-container">
<i class="icon far fa-comments"></i>
<span class="alt-text">WAPP</span>
</div>
</div>
<div class="widg launcher" id="open /Applications/Hyper.app">
<div class="icon-container" id="terminal-icon-container">
<i class="icon far fa-terminal"></i>
<span class="alt-text">TERM</span>
</div>
</div>
<div class="widg launcher" id="open /Applications/Atom.app">
<div class="icon-container" id="editor-icon-container">
<i class="icon far fa-code"></i>
<span class="alt-text">ATOM</span>
</div>
</div>
</div>
<!--
<div class="widg tray-button pinned yellow" id="player">
<div class="icon-container" id="player-icon-container">
<i class="icon fab fa-itunes-note"></i>
<span class="alt-text">PLAY</span>
</div>
</div>
</div>-->
<div class="tray" id="play-tray">
<div class="widg" id="play">
<div class="icon-container" id="play-icon-container">
<i class="fas fa-play" id="play-button"></i>
</div>
</div>
<div class="widg" id="next">
<div class="icon-container" id="next-icon-container">
<i class="fas fa-step-forward" id="next-button"></i>
</div>
</div>
<div class="widg" id="playing">
<span class="output nohidden" id='play-output'></span>
</div>
</div>
</div>
"""
update: ( output, domEl ) ->
output = output.split( /:::/g )
activedesk = output[0]
isitunesrunning = output[1]
isspotifyrunning = output[2]
isitunesplaying = output[3]
isspotifyplaying = output[4]
itunes = output[5]
spotify = output[6]
if isspotifyplaying
@handlePlayIcon(domEl, true)
@handlePlayIcon(domEl, true)
@run "osascript -e 'if application \"Spotify\" is running then tell application \"Spotify\" to if player state is playing then artist of current track & \" - \" & name of current track'", (err, output) ->
$(domEl).find('#play-output').text(output)
else if isitunesplaying
@handlePlayIcon(domEl, true)
@handlePlayIcon(domEl, true)
@run "osascript -e 'if application \"iTunes\" is running then tell application \"iTunes\" to if player state is playing then artist of current track & \" - \" & name of current track'", (err, output) ->
$(domEl).find('#play-output').text(output)
else if not isspotifyplaying && not isitunesplaying
@handlePlayIcon(domEl, false)
$("#play-output").text("")
if options.desktop is true
#$("#home").removeClass()
#$("#home").addClass("widg pinned tray-button #{ @getDesktopColor(activedesk) }")
if $("#active-desktop").text != activedesk
$("#active-desktop").text(activedesk)
#
# ─── HANDLES ─────────────────────────────────────────────────────────
#
getDesktopColor: (activedesk) ->
color = switch
when activedesk == "1" then "red"
when activedesk == "2" then "yellow"
when activedesk == "3" then "blue"
when activedesk == "4" then "magenta"
return color
handlePlay: (domEl, status) ->
@run "osascript -e 'tell application \"iTunes\" to playpause'"
@handlePlayIcon(domEl, status)
@refresh()
handlePlayIcon: (domEl, status) ->
if status == 'NULL'
if $(domEl).find('#play-button').hasClass('fa-play')
status = true
else
status = false
if status == true
$(domEl).find('#play-button').removeClass()
$(domEl).find('#play-list').removeClass("hidden")
$(domEl).find('#play-button').addClass('fas fa-pause')
else
$(domEl).find('#play-button').removeClass()
$(domEl).find('#play-button').addClass('fas fa-play')
$(domEl).find('#play-list').addClass("hidden")
handleNext: (domEl) ->
@run "osascript -e 'tell application \"iTunes\" to next track'"
$(domEl).find('#play-button').removeClass()
$(domEl).find('#play-button').addClass('fas fa-pause')
@refresh()
afterRender: (domEl) ->
$(domEl).on 'click', ".widg", (e) -> run $(e.target).attr('id')
$(domEl).on 'mouseover', ".widg", (e) => if not $(domEl).find( $($(e.target))).hasClass('tray-button') then $(domEl).find($($(e.target))).addClass('pinned')
$(domEl).on 'mouseout', ".widg", (e) => if not $(domEl).find( $($(e.target))).hasClass('tray-button') then $(domEl).find($($(e.target))).removeClass('pinned')
$(domEl).on 'click', '#play', => @handlePlay(domEl, 'NULL')
$(domEl).on 'click', '#next', => @handleNext(domEl)
$(domEl).on 'click', ".tray-button", (e) => $(domEl).find(".tray").toggleClass('hidden')