Skip to content
Navigation Menu
{{ message }}
forked from sachithkadamba/CocoaSampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttachedScripts.applescript
More file actions
executable file
·390 lines (323 loc) · 13 KB
/
Copy pathAttachedScripts.applescript
File metadata and controls
executable file
·390 lines (323 loc) · 13 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
(*
File: AttachedScripts.applescript
Abstract: These are the AppleScripts called by the main program. This file is compiled
at build time into the file AttachedScripts.scpt. We have added two new build
phases to accomplish this.
Version: 1.1
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
Inc. ("Apple") in consideration of your agreement to the following
terms, and your use, installation, modification or redistribution of
this Apple software constitutes acceptance of these terms. If you do
not agree with these terms, please do not use, install, modify or
redistribute this Apple software.
In consideration of your agreement to abide by the following terms, and
subject to these terms, Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this original Apple software (the
"Apple Software"), to use, reproduce, modify and redistribute the Apple
Software, with or without modifications, in source and/or binary forms;
provided that if you redistribute the Apple Software in its entirety and
without modifications, you must retain this notice and the following
text and disclaimers in all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or logos of Apple Inc. may
be used to endorse or promote products derived from the Apple Software
without specific prior written permission from Apple. Except as
expressly stated in this notice, no other rights or licenses, express or
implied, are granted by Apple herein, including but not limited to any
patent rights that may be infringed by your derivative works or by other
works in which the Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS IS" basis. APPLE
MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
Copyright (C) 2011 Apple Inc. All Rights Reserved.
*)
(* AttachedScripts.applescript
These are the AppleScripts called by the main program. This file is compiled
at build time into the file AttachedScripts.scpt. We have added two new build
phases to accomplish this.
1. The first build phase executes this command:
osacompile -d -o AttachedScripts.scpt AttachedScripts.applescript
This command compiles this source file 'AttachedScripts.applescript' saving the result
in the data fork of the file 'AttachedScripts.scpt'.
2. The second build phase simply copies both of the files 'AttachedScripts.scpt'
and 'AttachedScripts.applescript' into the final application's resources directory.
IMPORTANT: I have noticed that you need to 'clean' the build
before it will copy the compiled versions of these files over
to the resources directory.
Some interesting points to make here are:
(a) if at any time you want to reconfigure your application so that the scripts
do different things you can do so by editing this file and recompiling it to the
.scpt file using this command:
osacompile -d -o AttachedScripts.scpt AttachedScripts.applescript
(b) everything here is datafork based and does not require any resource forks. As
such, it's easily transportable to other file systems.
(c) Recompiling this script file does not require recompilation of your main
program, but it can significantly enhance the configurability of your application.
As well, it can defer some design and interoperability decisions until later in
the development cycle. Want to swap in a different app for some special task?
Just rewrite the script, your main program doesn't have to know about it...
(d) recompiling this script is even something that daring advanced users
with special requirements may want to do.
(c) because the main program only loads the precompiled
'AttachedScripts.scpt' your application does not bear any of the runtime
compilation costs that are involved. From the application's point of
view, it's just 'Load and go...'.
*)
(* HookUpToRemoteMachine
our app calls this script at application startup time. In this handler
we present the url selection dialog allowing the user to select
a remote machine where the iTunes application we want to control
is running. We store the remote machine address in the script's
property 'theRemoteURL' that is used by all of the other handlers
to direct commands to the iTunes app. This handler returns the error
number if an error ocurred or 0 indicating sucess. *)
property theRemoteURL : ""
on HookUpToRemoteMachine()
try
set theURL to choose URL showing Remote applications
using terms from application "iTunes"
tell application "iTunes" of machine theURL
set localVariable to sound volume (* try some command to verify the connection *)
end tell
end using terms from
set theRemoteURL to theURL
return 0
on error errmsg number errNum
return errNum
end try
end HookUpToRemoteMachine
(* ReportRemoteVolume
This handler calls the remote iTunes application to obtain the current
volume setting - an integer value between 0 and 100. NOTE: this
is the volume setting inside of iTunes and it is not the same
as the output volume setting for the entire remote machine. *)
on ReportRemoteVolume()
set theVolume to 0
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
set theVolume to sound volume
end tell
end using terms from
return theVolume
end ReportRemoteVolume
(* SetRemoteVolume
This handler calls the remote iTunes application to obtain the current
volume setting - an integer value between 0 and 100. NOTE: this
is the volume setting inside of iTunes and it is not the same
as the output volume setting for the entire remote machine. *)
on SetRemoteVolume(newVolume)
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
set sound volume to newVolume
end tell
end using terms from
end SetRemoteVolume
(* ReportRemotePlayerState
This handler calls the remote iTunes application to obtain the current
status of the player - a list of seven elements including
playing (0 or 1), playlist, track, position, duration,
statusstr, and volume . *)
on ReportRemotePlayerState()
set theResult to {0, "", "", 0, 0, "Not Playing", 0}
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
if player state is playing then
-- set up the status string
set statusStr to "Playing '" & name of current track & "' by '"
set statusStr to statusStr & artist of current track & "' from playlist '"
set statusStr to statusStr & name of current playlist & "'"
-- put together the result list
set theResult to {1, name of current playlist, name of current track}
set theResult to theResult & {player position, duration of current track}
set theResult to theResult & {statusStr, sound volume}
else
set theResult to {0, "", "", 0, 0, "Not Playing", sound volume}
end if
end tell
end using terms from
return theResult
end ReportRemotePlayerState
(* GongCurrentTrack is called when the user clicks on the
gong button. This handler disables the track that is currently
playing and skips ahead to the next track. If the player is not
playing, this handler does nothing. *)
on GongCurrentTrack()
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
if player state is playing then
set enabled of current track to false
next track
end if
end tell
end using terms from
end GongCurrentTrack
(* SwitchRemotePlayerState is called when the user clicks on the
play/pause button. This routine simply turns the remote player on
or off. *)
on SwitchRemotePlayerState(newState)
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
if (newState is equal to 1) then
play
else
pause
end if
end tell
end using terms from
end SwitchRemotePlayerState
(* GoToNextTrack is called when the user clicks on the
skip ahead button. This routine advances the player to the
next track. *)
on GoToNextTrack()
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
next track
end tell
end using terms from
end GoToNextTrack
(* GoToPreviousTrack is called when the user clicks on the
skip back button. This routine asks the player to go back
to the previous track. *)
on GoToPreviousTrack()
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
previous track
end tell
end using terms from
end GoToPreviousTrack
(* GetPlaylistListing is called during program startup to retrieve
a list of the names of all of all of the playlists on the remote machine. *)
on GetPlaylistListing()
set nameList to {}
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
set nameList to get name of every playlist
end tell
end using terms from
return nameList
end GetPlaylistListing
(* PlayTrackFromPlaylist is when the user double clicks on a track name
in the track list. This handler receives a playlist name and the name of
the track and it asks the player to play that track. *)
on PlayTrackFromPlaylist(playlistName, trackName)
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
tell source "Library"
tell playlist playlistName
tell track trackName
play
end tell
end tell
end tell
end tell
end using terms from
end PlayTrackFromPlaylist
(* GetPlaylistTracks is called when ever the user clicks on a new playlist
name in the list of displayed playlists. Here we return a list containing
all of the names of the tracks in the selected playlist. *)
on GetPlaylistTracks(playlistName)
set theTracks to {}
try
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
tell source "Library"
tell playlist playlistName
set theTracks to get name of every track
end tell
end tell
end tell
end using terms from
on error
return theTracks
end try
return theTracks
end GetPlaylistTracks
(* GetPlaylistShuffle returns an integer value (0 or 1) reflecting
the status of the shuffle setting for the named playlist. *)
on GetPlaylistShuffle(playlistName)
set shuffleSetting to 0
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
tell source "Library"
tell playlist playlistName
if shuffle then
set shuffleSetting to 1
else
set shuffleSetting to 0
end if
end tell
end tell
end tell
end using terms from
return shuffleSetting
end GetPlaylistShuffle
(* SetPlaylistShuffle changes the current shuffle setting for
the named playlist to shuffleSetting. shuffleSetting should
be an integer value of either 0 (for off) or 1 (for on). *)
on SetPlaylistShuffle(playlistName, shuffleSetting)
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
tell source "Library"
tell playlist playlistName
if shuffleSetting is equal to 1 then
set shuffle to true
else
set shuffle to false
end if
end tell
end tell
end tell
end using terms from
end SetPlaylistShuffle
(* GetPlaylistRepeat returns an integer value of 0, for repeat off,
1, for repeat all, or 2, for repeat one, reflecting the state of
the repeat setting for the named playlist. *)
on GetPlaylistRepeat(playlistName)
set repeatSetting to 0
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
tell source "Library"
tell playlist playlistName
if (song repeat is off) then
set repeatSetting to 0
else if (song repeat is all) then
set repeatSetting to 1
else if (song repeat is one) then
set repeatSetting to 2
end if
end tell
end tell
end tell
end using terms from
return repeatSetting
end GetPlaylistRepeat
(* SetPlaylistRepeat is called to change the repeat setting
for the named playlist. repeatSetting should be a either
0, 1 or 2 representing 'repeat off', 'repeat all', or
'repeat one' respectively. *)
on SetPlaylistRepeat(playlistName, repeatSetting)
using terms from application "iTunes"
tell application "iTunes" of machine theRemoteURL
tell source "Library"
tell playlist playlistName
if (repeatSetting is equal to 0) then
set song repeat to off
else if (repeatSetting is equal to 1) then
set song repeat to all
else if (repeatSetting is equal to 2) then
set song repeat to one
end if
end tell
end tell
end tell
end using terms from
end SetPlaylistRepeat
You can’t perform that action at this time.
