Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
MyScriptsGlue.h
/* |
File: MyScriptsGlue.h |
Description: |
routines providing the c glue code for calling the AppleScripts |
defined in the file AddOnScripts.applescript. The routines in this |
file are constructed to provide an interface between your |
application and the scripts defined in AddOnScripts.applescript. Though |
the scripts themselves may be changed dramatically for different purposes, |
requirements, and server applications that are called by the scripts, there |
is no need to change any of the routines defined in this file (unless, of |
course, you're adding new ones or additional functionality). |
Author: JM |
Copyright: Copyright (c) 2003 Apple Computer, Inc. All rights reserved. |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, 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 Computer, 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. |
Change History (most recent first): |
Fri, Aug 29, 2000 -- created |
*/ |
#ifndef __MYSCRIPTSGLUE__ |
#define __MYSCRIPTSGLUE__ |
#include <Carbon/Carbon.h> |
/* routines providing the c glue code for calling the AppleScripts |
defined in the file AddOnScripts.applescript. The routines in this |
file are constructed to provide an interface between your |
application and the scripts defined in AddOnScripts.applescript. Though |
the scripts themselves may be changed dramatically for different purposes, |
requirements, and server applications that are called by the scripts, there |
is no need to change any of the routines defined in this file (unless, of |
course, you're adding new ones or additional functionality). */ |
/* OpenMyScriptsGlue initializes the globals used by the routines |
in this module. You should call this routine first before trying |
to call any of the scripts herein. */ |
OSStatus OpenMyScriptsGlue(void); |
/* CloseMyScriptsGlue releases all of the storage and resources |
allocated by OpenMyScriptsGlue. Call this routine when you |
are done with the scripts. */ |
OSStatus CloseMyScriptsGlue(void); |
/* script_callnamedhandler is the c glue code for the simple handlers with no |
parameters in the script file. This is a simple generic utility for calling |
simple handlers with no parameters. |
on handlername() |
.... |
return "optional result" |
end handlername |
set theResult to NULL if you're not interested in receiving a result back from |
the handler. |
*/ |
OSStatus script_callnamedhandler(char* handlername, AEDesc *theResult); |
/* script_selectfile is the c glue code for the following script in |
our scripts file: |
on selectfile() |
set x to choose file |
return x |
end selectfile |
*/ |
OSStatus script_selectfile(CFStringRef thePromptText, AliasHandle *theFile); |
/* script_displayfile is the c glue code for the following script in |
our scripts file: |
on displayfile(theFile) |
ignoring application responses |
tell application "Finder" |
activate |
select theFile |
end tell |
end ignoring |
end displayfile |
Of interest here is the 'ignoring application responses' block. Essentially, |
that means that this script will complete and return possibly before the finder |
has completed displaying the file. In cases where you don't need a result right |
away, this can be useful to speed things up because your app doesn't need to |
wait for other apps to finish what you're asking them to do. |
*/ |
OSStatus script_displayfile(AliasHandle targetFile); |
/* script_displaymessage is the c glue code for the following script in |
our scripts file: |
on displaystring(message) |
display dialog message |
end displaystring |
*/ |
OSStatus script_displaymessage(CFStringRef theMessageText); |
/* script_getfolderItems is the c glue code for the following script in |
our scripts file: |
on getfolderItems(promptstring) |
set theFolder to choose folder with prompt promptstring |
set folderPath to theFolder as string |
set folderItems to list folder theFolder |
set theList to {} |
repeat with i in folderItems |
set nthName to i as string |
if nthName does not start with "." then |
set nthItem to {nthName, (folderPath & nthName) as alias} |
copy nthItem to the end of theList |
end if |
end repeat |
return theList |
end getfolderItems |
*/ |
OSStatus script_getfolderitems(CFStringRef thePromptText, AEDescList *itemsList); |
/* script_filetostring is the c glue code for the following script in |
our scripts file: |
on filetostring(theFile) |
return (theFile as string) |
end filetostring |
*/ |
OSStatus script_filetostring(AliasHandle targetFile, CFStringRef *theFileString); |
/* script_getfilecomment is the c glue code for the following script in |
our scripts file: |
on getfilecomment(theFile) |
tell application "Finder" |
set x to comment of theFile |
end tell |
return x |
end getfilecomment |
*/ |
OSStatus script_getfilecomment(AliasHandle targetFile, CFStringRef *theFileComment); |
/* script_setfilecomment is the c glue code for the following script in |
our scripts file: |
on setfilecomment(theFile, thecomment) |
tell application "Finder" |
set (comment of theFile) to thecomment |
end tell |
return thecomment |
end setfilecomment |
*/ |
OSStatus script_setfilecomment(AliasHandle targetFile, CFStringRef theFileComment); |
#endif |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-09-04