1 /*****************************************************************************
2 * applescript.m: MacOS X AppleScript support
3 *****************************************************************************
4 * Copyright (C) 2002-2009 the VideoLAN team
7 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include "applescript.h"
29 #include "CoreInteraction.h"
31 /*****************************************************************************
32 * VLGetURLScriptCommand implementation
33 *****************************************************************************/
34 @implementation VLGetURLScriptCommand
36 - (id)performDefaultImplementation {
37 NSString *o_command = [[self commandDescription] commandName];
38 NSString *o_urlString = [self directParameter];
40 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 );
44 if( p_playlist == NULL )
52 input_item_t *p_input;
54 p_input = input_item_New( [o_urlString fileSystemRepresentation],
55 [[[NSFileManager defaultManager]
56 displayNameAtPath: o_urlString] UTF8String] );
57 /* FIXME: playlist_AddInput() can fail */
58 playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
59 PLAYLIST_END, true, pl_Unlocked );
61 vlc_gc_decref( p_input );
63 o_url = [NSURL fileURLWithPath: o_urlString];
66 [[NSDocumentController sharedDocumentController]
67 noteNewRecentDocumentURL: o_url];
77 /*****************************************************************************
78 * VLControlScriptCommand implementation
79 *****************************************************************************/
81 * This entire control command needs a better design. more object oriented.
82 * Applescript developers would be very welcome (hartman)
84 @implementation VLControlScriptCommand
86 - (id)performDefaultImplementation {
87 NSString *o_command = [[self commandDescription] commandName];
89 intf_thread_t * p_intf = VLCIntf;
90 playlist_t * p_playlist = pl_Get( p_intf );
91 if( p_playlist == NULL )
96 if ( [o_command isEqualToString:@"play"] )
98 [[VLCCoreInteraction sharedInstance] play];
100 else if ( [o_command isEqualToString:@"stop"] )
102 [[VLCCoreInteraction sharedInstance] stop];
104 else if ( [o_command isEqualToString:@"previous"] )
106 [[VLCCoreInteraction sharedInstance] previous];
108 else if ( [o_command isEqualToString:@"next"] )
110 [[VLCCoreInteraction sharedInstance] next];
112 else if ( [o_command isEqualToString:@"fullscreen"] )
114 [[VLCCoreInteraction sharedInstance] toggleFullscreen];
116 else if ( [o_command isEqualToString:@"mute"] )
118 [[VLCCoreInteraction sharedInstance] mute];
120 else if ( [o_command isEqualToString:@"volumeUp"] )
122 [[VLCCoreInteraction sharedInstance] volumeUp];
124 else if ( [o_command isEqualToString:@"volumeDown"] )
126 [[VLCCoreInteraction sharedInstance] volumeDown];
133 /*****************************************************************************
134 * Category that adds AppleScript support to NSApplication
135 *****************************************************************************/
136 @implementation NSApplication(ScriptSupport)
138 - (BOOL) scriptFullscreenMode {
139 vout_thread_t * p_vout = getVout();
142 BOOL b_value = var_GetBool( p_vout, "fullscreen");
143 vlc_object_release( p_vout );
146 - (void) setScriptFullscreenMode: (BOOL) mode {
147 vout_thread_t * p_vout = getVout();
150 if (var_GetBool( p_vout, "fullscreen") == mode)
152 vlc_object_release( p_vout );
155 vlc_object_release( p_vout );
156 [[VLCCoreInteraction sharedInstance] toggleFullscreen];