1 /*****************************************************************************
2 * applescript.m: MacOS X AppleScript support
3 *****************************************************************************
4 * Copyright (C) 2002-2012 VLC authors and VideoLAN
7 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8 * Felix Paul Kühne <fkuehne at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
29 #include "applescript.h"
30 #include "CoreInteraction.h"
31 #include "vlc_aout_intf.h"
33 /*****************************************************************************
34 * VLGetURLScriptCommand implementation
35 *****************************************************************************/
36 @implementation VLGetURLScriptCommand
38 - (id)performDefaultImplementation {
39 NSString *o_command = [[self commandDescription] commandName];
40 NSString *o_urlString = [self directParameter];
42 if ( [o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"] )
44 intf_thread_t * p_intf = VLCIntf;
45 playlist_t * p_playlist = pl_Get( p_intf );
46 if( p_playlist == NULL )
54 input_item_t *p_input;
56 p_input = input_item_New( [o_urlString fileSystemRepresentation],
57 [[[NSFileManager defaultManager]
58 displayNameAtPath: o_urlString] UTF8String] );
59 /* FIXME: playlist_AddInput() can fail */
60 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
61 PLAYLIST_END, true, pl_Unlocked );
63 vlc_gc_decref( p_input );
65 o_url = [NSURL fileURLWithPath: o_urlString];
68 [[NSDocumentController sharedDocumentController]
69 noteNewRecentDocumentURL: o_url];
79 /*****************************************************************************
80 * VLControlScriptCommand implementation
81 *****************************************************************************/
83 * This entire control command needs a better design. more object oriented.
84 * Applescript developers would be very welcome (hartman)
86 @implementation VLControlScriptCommand
88 - (id)performDefaultImplementation {
89 NSString *o_command = [[self commandDescription] commandName];
90 NSString *o_parameter = [self directParameter];
92 intf_thread_t * p_intf = VLCIntf;
93 playlist_t * p_playlist = pl_Get( p_intf );
94 if( p_playlist == NULL )
99 if ( [o_command isEqualToString:@"play"] )
101 [[VLCCoreInteraction sharedInstance] play];
103 else if ( [o_command isEqualToString:@"stop"] )
105 [[VLCCoreInteraction sharedInstance] stop];
107 else if ( [o_command isEqualToString:@"previous"] )
109 [[VLCCoreInteraction sharedInstance] previous];
111 else if ( [o_command isEqualToString:@"next"] )
113 [[VLCCoreInteraction sharedInstance] next];
115 else if ( [o_command isEqualToString:@"fullscreen"] )
117 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
119 else if ( [o_command isEqualToString:@"mute"] )
121 [[VLCCoreInteraction sharedInstance] mute];
123 else if ( [o_command isEqualToString:@"volumeUp"] )
125 [[VLCCoreInteraction sharedInstance] volumeUp];
127 else if ( [o_command isEqualToString:@"volumeDown"] )
129 [[VLCCoreInteraction sharedInstance] volumeDown];
131 else if ( [o_command isEqualToString:@"stepForward"] )
133 //default: forwardShort
136 int i_parameter = [o_parameter intValue];
140 [[VLCCoreInteraction sharedInstance] forwardExtraShort];
143 [[VLCCoreInteraction sharedInstance] forwardShort];
146 [[VLCCoreInteraction sharedInstance] forwardMedium];
149 [[VLCCoreInteraction sharedInstance] forwardLong];
152 [[VLCCoreInteraction sharedInstance] forwardShort];
158 [[VLCCoreInteraction sharedInstance] forwardShort];
161 else if ( [o_command isEqualToString:@"stepBackward"] )
163 //default: backwardShort
166 int i_parameter = [o_parameter intValue];
170 [[VLCCoreInteraction sharedInstance] backwardExtraShort];
173 [[VLCCoreInteraction sharedInstance] backwardShort];
176 [[VLCCoreInteraction sharedInstance] backwardMedium];
179 [[VLCCoreInteraction sharedInstance] backwardLong];
182 [[VLCCoreInteraction sharedInstance] backwardShort];
188 [[VLCCoreInteraction sharedInstance] backwardShort];
196 /*****************************************************************************
197 * Category that adds AppleScript support to NSApplication
198 *****************************************************************************/
199 @implementation NSApplication(ScriptSupport)
201 - (BOOL) scriptFullscreenMode {
202 vout_thread_t * p_vout = getVout();
205 BOOL b_value = var_GetBool( p_vout, "fullscreen");
206 vlc_object_release( p_vout );
209 - (void) setScriptFullscreenMode: (BOOL) mode {
210 vout_thread_t * p_vout = getVout();
213 if (var_GetBool( p_vout, "fullscreen") == mode)
215 vlc_object_release( p_vout );
218 vlc_object_release( p_vout );
219 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
223 return [[VLCCoreInteraction sharedInstance] isMuted];
227 return [[VLCCoreInteraction sharedInstance] isPlaying];
230 - (int) audioVolume {
231 return ( [[VLCCoreInteraction sharedInstance] volume] );
234 - (void) setAudioVolume: (int) i_audioVolume {
235 [[VLCCoreInteraction sharedInstance] setVolume:(int)i_audioVolume];
238 - (int) currentTime {
239 return [[VLCCoreInteraction sharedInstance] currentTime];
242 - (void) setCurrentTime: (int) i_currentTime {
244 [[VLCCoreInteraction sharedInstance] setCurrentTime:i_currentTime];
248 //TODO:whenever VLC should implement NSDocument, the methods below should move or be additionaly implemented in the NSDocument category
249 - (int) durationOfCurrentItem {
250 return [[VLCCoreInteraction sharedInstance] durationOfCurrentPlaylistItem];
253 - (NSString*) pathOfCurrentItem {
254 return [[[VLCCoreInteraction sharedInstance] URLOfCurrentPlaylistItem] path];
257 - (NSString*) nameOfCurrentItem {
258 return [[VLCCoreInteraction sharedInstance] nameOfCurrentPlaylistItem];