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"
32 /*****************************************************************************
33 * VLGetURLScriptCommand implementation
34 *****************************************************************************/
35 @implementation VLGetURLScriptCommand
37 - (id)performDefaultImplementation {
38 NSString *o_command = [[self commandDescription] commandName];
39 NSString *o_urlString = [self directParameter];
41 if ([o_command isEqualToString:@"GetURL"] || [o_command isEqualToString:@"OpenURL"]) {
42 intf_thread_t * p_intf = VLCIntf;
43 playlist_t * p_playlist = pl_Get(p_intf);
47 input_item_t *p_input;
50 p_input = input_item_New([o_urlString fileSystemRepresentation],
51 [[[NSFileManager defaultManager]
52 displayNameAtPath: o_urlString] UTF8String]);
56 returnValue = playlist_AddInput(p_playlist, p_input, PLAYLIST_INSERT,
57 PLAYLIST_END, true, pl_Unlocked);
58 vlc_gc_decref(p_input);
60 if (returnValue != VLC_SUCCESS)
63 o_url = [NSURL fileURLWithPath: o_urlString];
65 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: o_url];
74 /*****************************************************************************
75 * VLControlScriptCommand implementation
76 *****************************************************************************/
78 * This entire control command needs a better design. more object oriented.
79 * Applescript developers would be very welcome (hartman)
81 @implementation VLControlScriptCommand
83 - (id)performDefaultImplementation {
84 NSString *o_command = [[self commandDescription] commandName];
85 NSString *o_parameter = [self directParameter];
87 intf_thread_t * p_intf = VLCIntf;
88 playlist_t * p_playlist = pl_Get(p_intf);
90 if ([o_command isEqualToString:@"play"])
91 [[VLCCoreInteraction sharedInstance] play];
92 else if ([o_command isEqualToString:@"stop"])
93 [[VLCCoreInteraction sharedInstance] stop];
94 else if ([o_command isEqualToString:@"previous"])
95 [[VLCCoreInteraction sharedInstance] previous];
96 else if ([o_command isEqualToString:@"next"])
97 [[VLCCoreInteraction sharedInstance] next];
98 else if ([o_command isEqualToString:@"fullscreen"])
99 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
100 else if ([o_command isEqualToString:@"mute"])
101 [[VLCCoreInteraction sharedInstance] setMute: YES];
102 else if ([o_command isEqualToString:@"volumeUp"])
103 [[VLCCoreInteraction sharedInstance] volumeUp];
104 else if ([o_command isEqualToString:@"volumeDown"])
105 [[VLCCoreInteraction sharedInstance] volumeDown];
106 else if ([o_command isEqualToString:@"stepForward"]) {
107 //default: forwardShort
109 int i_parameter = [o_parameter intValue];
110 switch (i_parameter) {
112 [[VLCCoreInteraction sharedInstance] forwardExtraShort];
115 [[VLCCoreInteraction sharedInstance] forwardShort];
118 [[VLCCoreInteraction sharedInstance] forwardMedium];
121 [[VLCCoreInteraction sharedInstance] forwardLong];
124 [[VLCCoreInteraction sharedInstance] forwardShort];
128 [[VLCCoreInteraction sharedInstance] forwardShort];
129 } else if ([o_command isEqualToString:@"stepBackward"]) {
130 //default: backwardShort
132 int i_parameter = [o_parameter intValue];
133 switch (i_parameter) {
135 [[VLCCoreInteraction sharedInstance] backwardExtraShort];
138 [[VLCCoreInteraction sharedInstance] backwardShort];
141 [[VLCCoreInteraction sharedInstance] backwardMedium];
144 [[VLCCoreInteraction sharedInstance] backwardLong];
147 [[VLCCoreInteraction sharedInstance] backwardShort];
151 [[VLCCoreInteraction sharedInstance] backwardShort];
158 /*****************************************************************************
159 * Category that adds AppleScript support to NSApplication
160 *****************************************************************************/
161 @implementation NSApplication(ScriptSupport)
163 - (BOOL)scriptFullscreenMode {
164 vout_thread_t * p_vout = getVoutForActiveWindow();
167 BOOL b_value = var_GetBool(p_vout, "fullscreen");
168 vlc_object_release(p_vout);
172 - (void)setScriptFullscreenMode:(BOOL)mode {
173 vout_thread_t * p_vout = getVoutForActiveWindow();
176 if (var_GetBool(p_vout, "fullscreen") == mode) {
177 vlc_object_release(p_vout);
180 vlc_object_release(p_vout);
181 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
185 return [[VLCCoreInteraction sharedInstance] mute];
189 intf_thread_t *p_intf = VLCIntf;
193 input_thread_t * p_input = pl_CurrentInput(p_intf);
197 input_state_e i_state = ERROR_S;
198 input_Control(p_input, INPUT_GET_STATE, &i_state);
199 vlc_object_release(p_input);
201 return ((i_state == OPENING_S) || (i_state == PLAYING_S));
204 - (int) audioVolume {
205 return ([[VLCCoreInteraction sharedInstance] volume]);
208 - (void) setAudioVolume:(int)i_audioVolume {
209 [[VLCCoreInteraction sharedInstance] setVolume:(int)i_audioVolume];
212 - (int) currentTime {
213 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
214 int64_t i_currentTime = -1;
217 return i_currentTime;
219 input_Control(p_input, INPUT_GET_TIME, &i_currentTime);
220 vlc_object_release(p_input);
222 return (int)(i_currentTime / 1000000);
225 - (void) setCurrentTime:(int)i_currentTime {
227 int64_t i64_value = (int64_t)i_currentTime;
228 input_thread_t * p_input = pl_CurrentInput(VLCIntf);
233 input_Control(p_input, INPUT_SET_TIME, (int64_t)(i64_value * 1000000));
234 vlc_object_release(p_input);
238 - (int) durationOfCurrentItem {
239 return [[VLCCoreInteraction sharedInstance] durationOfCurrentPlaylistItem];
242 - (NSString*) pathOfCurrentItem {
243 return [[[VLCCoreInteraction sharedInstance] URLOfCurrentPlaylistItem] path];
246 - (NSString*) nameOfCurrentItem {
247 return [[VLCCoreInteraction sharedInstance] nameOfCurrentPlaylistItem];