1 /*****************************************************************************
2 * applescript.m: MacOS X AppleScript support
3 *****************************************************************************
4 * Copyright (C) 2002-2013 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 #import "applescript.h"
30 #import "CoreInteraction.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 BOOL b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
45 NSURL * o_url = [NSURL fileURLWithPath: o_urlString];
47 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_url];
49 NSMutableArray *o_result = [NSMutableArray arrayWithObject:[NSDictionary dictionaryWithObject:o_urlString forKey:@"ITEM_URL"]];
52 [[[VLCMain sharedInstance] playlist] appendArray: o_result atPos: -1 enqueue: NO];
54 [[[VLCMain sharedInstance] playlist] appendArray: o_result atPos: -1 enqueue: YES];
63 /*****************************************************************************
64 * VLControlScriptCommand implementation
65 *****************************************************************************/
67 * This entire control command needs a better design. more object oriented.
68 * Applescript developers would be very welcome (hartman)
70 @implementation VLControlScriptCommand
72 - (id)performDefaultImplementation {
73 NSString *o_command = [[self commandDescription] commandName];
74 NSString *o_parameter = [self directParameter];
76 intf_thread_t * p_intf = VLCIntf;
77 playlist_t * p_playlist = pl_Get(p_intf);
79 if ([o_command isEqualToString:@"play"])
80 [[VLCCoreInteraction sharedInstance] playOrPause];
81 else if ([o_command isEqualToString:@"stop"])
82 [[VLCCoreInteraction sharedInstance] stop];
83 else if ([o_command isEqualToString:@"previous"])
84 [[VLCCoreInteraction sharedInstance] previous];
85 else if ([o_command isEqualToString:@"next"])
86 [[VLCCoreInteraction sharedInstance] next];
87 else if ([o_command isEqualToString:@"fullscreen"])
88 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
89 else if ([o_command isEqualToString:@"mute"])
90 [[VLCCoreInteraction sharedInstance] setMute: YES];
91 else if ([o_command isEqualToString:@"volumeUp"])
92 [[VLCCoreInteraction sharedInstance] volumeUp];
93 else if ([o_command isEqualToString:@"volumeDown"])
94 [[VLCCoreInteraction sharedInstance] volumeDown];
95 else if ([o_command isEqualToString:@"stepForward"]) {
96 //default: forwardShort
98 int i_parameter = [o_parameter intValue];
99 switch (i_parameter) {
101 [[VLCCoreInteraction sharedInstance] forwardExtraShort];
104 [[VLCCoreInteraction sharedInstance] forwardShort];
107 [[VLCCoreInteraction sharedInstance] forwardMedium];
110 [[VLCCoreInteraction sharedInstance] forwardLong];
113 [[VLCCoreInteraction sharedInstance] forwardShort];
117 [[VLCCoreInteraction sharedInstance] forwardShort];
118 } else if ([o_command isEqualToString:@"stepBackward"]) {
119 //default: backwardShort
121 int i_parameter = [o_parameter intValue];
122 switch (i_parameter) {
124 [[VLCCoreInteraction sharedInstance] backwardExtraShort];
127 [[VLCCoreInteraction sharedInstance] backwardShort];
130 [[VLCCoreInteraction sharedInstance] backwardMedium];
133 [[VLCCoreInteraction sharedInstance] backwardLong];
136 [[VLCCoreInteraction sharedInstance] backwardShort];
140 [[VLCCoreInteraction sharedInstance] backwardShort];
147 /*****************************************************************************
148 * Category that adds AppleScript support to NSApplication
149 *****************************************************************************/
150 @implementation NSApplication(ScriptSupport)
152 - (BOOL)scriptFullscreenMode {
153 vout_thread_t * p_vout = getVoutForActiveWindow();
156 BOOL b_value = var_GetBool(p_vout, "fullscreen");
157 vlc_object_release(p_vout);
161 - (void)setScriptFullscreenMode:(BOOL)mode {
162 vout_thread_t * p_vout = getVoutForActiveWindow();
165 if (var_GetBool(p_vout, "fullscreen") == mode) {
166 vlc_object_release(p_vout);
169 vlc_object_release(p_vout);
170 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
174 return [[VLCCoreInteraction sharedInstance] mute];
178 intf_thread_t *p_intf = VLCIntf;
182 input_thread_t * p_input = pl_CurrentInput(p_intf);
186 input_state_e i_state = ERROR_S;
187 input_Control(p_input, INPUT_GET_STATE, &i_state);
188 vlc_object_release(p_input);
190 return ((i_state == OPENING_S) || (i_state == PLAYING_S));
193 - (int) audioVolume {
194 return ([[VLCCoreInteraction sharedInstance] volume]);
197 - (void) setAudioVolume:(int)i_audioVolume {
198 [[VLCCoreInteraction sharedInstance] setVolume:(int)i_audioVolume];
201 - (int) currentTime {
202 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
203 int64_t i_currentTime = -1;
206 return i_currentTime;
208 input_Control(p_input, INPUT_GET_TIME, &i_currentTime);
209 vlc_object_release(p_input);
211 return (int)(i_currentTime / 1000000);
214 - (void) setCurrentTime:(int)i_currentTime {
216 int64_t i64_value = (int64_t)i_currentTime;
217 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
222 input_Control(p_input, INPUT_SET_TIME, (int64_t)(i64_value * 1000000));
223 vlc_object_release(p_input);
227 - (int) durationOfCurrentItem {
228 return [[VLCCoreInteraction sharedInstance] durationOfCurrentPlaylistItem];
231 - (NSString*) pathOfCurrentItem {
232 return [[[VLCCoreInteraction sharedInstance] URLOfCurrentPlaylistItem] path];
235 - (NSString*) nameOfCurrentItem {
236 return [[VLCCoreInteraction sharedInstance] nameOfCurrentPlaylistItem];