-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing1.html
executable file
·521 lines (380 loc) · 17.3 KB
/
listing1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>EmbededAppleScripts - /AddOnScripts.applescript</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/ScriptingAutomation/index.html">Scripting & Automation</a> > <a href="../../samplecode/ScriptingAutomation/idxCarbon-date.html">Carbon</a> > <A HREF="javascript:location.replace('index.html');">EmbededAppleScripts</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">EmbededAppleScripts</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/AddOnScripts.applescript</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/AddOnScripts.applescript</option>
<option value="listing2.html">/FinderCommentWindow.c</option>
<option value="listing3.html">/FinderCommentWindow.h</option>
<option value="listing4.html">/main.c</option>
<option value="listing5.html">/MainWindow.c</option>
<option value="listing6.html">/MainWindow.h</option>
<option value="listing7.html">/MyScriptsGlue.c</option>
<option value="listing8.html">/MyScriptsGlue.h</option>
<option value="listing9.html">/readme.txt</option>
<option value="listing10.html">/ScriptSupport.c</option>
<option value="listing11.html">/ScriptSupport.h</option></select>
</p>
</form>
<p><strong><a href="EmbededAppleScripts.zip">Download Sample</a></strong> (“EmbededAppleScripts.zip”, 119.6K)<BR>
<strong><a href="EmbededAppleScripts.dmg">Download Sample</a></strong> (“EmbededAppleScripts.dmg”, 171.5K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">(* File: AddOnScripts.applescript Description: These are the AppleScripts called by the main program. This file is compiled at build time into the file AddOnScripts.scpt. We have added two new build phases to accomplish this. 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*)(* AddOnScripts.applescriptThese are the AppleScripts called by the main program. This file is compiledat build time into the file AddOnScripts.scpt. We have added two new buildphases to accomplish this.1. The first build phase executes this command: osacompile -d -o AddOnScripts.scpt AddOnScripts.applescriptThis command compiles this source file 'AddOnScripts.applescript' saving the resultin the data fork of the file 'AddOnScripts.scpt'.2. The second build phase simply copies both of the files 'AddOnScripts.scpt'and 'AddOnScripts.applescript' into the final application's resources directory.IMPORTANT: I have noticed that you need to 'clean' the buildbefore it will copy the compiled versions of these files overto the resources directory. Some interesting points to make here are:(a) if at any time you want to reconfigure your application so that the scriptsdo different things you can do so by editing this file and recompiling it to the.scpt file using this command: osacompile -d -o AddOnScripts.scpt AddOnScripts.applescript(b) everything here is datafork based and does not require any resource forks. Assuch, it's easily transportable to other file systems.(c) Recompiling this script file does not require recompilation of your mainprogram, but it can significantly enhance the configurability of your application.As well, it can defer some design and interoperability decisions until later inthe development cycle. Want to swap in a different app for some special task?Just rewrite the script, your main program doesn't have to know about it...(d) recompiling this script is even something that daring advanced userswith special requirements may want to do.(c) because the main program only loads the precompiled'AddOnScripts.scpt' your application does not bear any of the runtimecompilation costs that are involved. From the application's point ofview, it's just 'Load and go...'.*)(* gMyVariable global variable we define and set in our startup and shutdownroutines. No particular value really, other than to illustratethat a script can contain persistent state that lasts throughprogram execution. *)property gMyVariable : "nods..."(* appstartup our app calls this script at application startup time. Here, we coulddo some special startup tasks such as initalizing script globals,opening connections to data bases, opening files, etc... here,we display a dialog and initialize one of our global variables. *)on appstartup() -- show the startup state display dialog "here's our startup script, global = " & gMyVariable -- change the variable set gMyVariable to "spits!" end appstartup(* appshutdown our app calls this script at application shutdown time. Here, we coulddo some special shutdown tasks such as closing data base connections,closing files, etc... here, we display a dialog showing the value we setthe global to in our startup script and then we change itto something else before quitting. *)on appshutdown() -- show the state we set it to at startup display dialog "here's our shutdown script, global = " & gMyVariable -- change it for kicks... set gMyVariable to "barrel!" end appshutdown(* displaystring display a messaage string in a dialog. *)on displaystring(message) -- show our message display dialog message end displaystring(* selectfile displays a file selection dialog box allowing the user to selecta file of type text. the prompt string appears to be ignored bythe 'choose file' command, but I put it there anyway just toshow how to pass a string parameter from the application tothe script. NOTE: it would be just as simple to ask the finderfor the current selection and then use that! *)on selectfile(promptstring) -- select a file, save it in variable 'theFile' set theFile to choose file of type {"TEXT"} with prompt promptstring -- return the alias to the caller return theFile end selectfile(* filetostring we use this routine to convert a file alias into a string for displayin a window. *)on filetostring(theFile) -- simply coerce the file alias to a string return (theFile as string) end filetostring(* displayfile We use this routine to display a file. right now, it asks the finderto select and display the item in a window. By adding the 'ignoring application responses', we are basically saying that thescript will not wait for the finder to finish before returning tothe main application. i.e. we get control of the pc back possiblybefore the finder has finished displaying the file. *)on displayfile(theFile) -- don't wait for the finder to send back any results ignoring application responses -- Finder 'FULL ON!!!' tell application "Finder" -- switch to the Finder process activate -- select the file select theFile end tell end ignoringend displayfile(* getfilecomment retrieves the 'Get Info...' Finder comment associatedwith the item referenced by the alias 'theFile'. *)on getfilecomment(theFile) -- with the Finder... tell application "Finder" -- copy the Finder comment to the local -- variable theComment set thecomment to comment of theFile end tell -- return the comment return thecomment end getfilecomment(* setfilecomment changes the 'Get Info...' Finder comment associatedwith the item referenced by the alias 'theFile' to thenew comment text. It also returns the new comment text,but we ignore that in our application (and we did thaton purpose to illustrate that it is okay to do that andit won't cause a memory leak!). *)on setfilecomment(theFile, thecomment) -- with the Finder... tell application "Finder" -- set the file's comment property comment set (comment of theFile) to thecomment end tell -- return the new comment to the caller -- which, of course, we promptly ignore -- in our application... return thecomment end setfilecomment(* getfolderItems illustrates how a script can return a complex set of manyvalues to the calling application. Here, we prompt theuser to select a folder. If they do so, then we build alist of all of the items in the folder. For each itemthat we include in the list, we save a list containingtwo items: the name of the item, and an alias referring to it.So basically, we return a list of two item lists like so:{ { name of item 1, alias to item 1 }, { name of item 2, alias to item 2 }, ... { name of item n, alias to item n }}In our application, we use the names to display the namesof the items in the list, and we use the alias records toretrieve the get info comments. *)on getfolderItems(promptstring) -- initialize our list result to empty set theList to {} -- ask the user to pick a folder set theFolder to choose folder with prompt promptstring -- using the Finder... tell application "Finder" -- enumerate all of the items in the folder set folderItems to contents of folder theFolder -- for each of the items returned... repeat with nthItem in folderItems -- create a new list element (a two element list -- composed of the item name and an alias referring -- to the item set nthListElement to {name of nthItem, (nthItem as alias)} -- copy the new element to the end of the list copy nthListElement to the end of theList end repeat end tell -- return the new list return theListend getfolderItems(* getfinderselection returns exactly the same results as the getfolderItemsroutine, except it returns a list of all of the itemsthat are selected in the Finder rather than promptingthe user to select a folder. *)on getfinderselection() -- initialize our list result to empty set theList to {} -- using the Finder... tell application "Finder" -- enumerate all of the items in the current selection set folderItems to the selection -- for each of the items returned... repeat with nthItem in folderItems -- create a new list element (a two element list -- composed of the item name and an alias referring -- to the item set nthListElement to {name of nthItem, (nthItem as alias)} -- copy the new element to the end of the list copy nthListElement to the end of theList end repeat end tell -- if there's no result, explain why so everyone's -- not confused by the lack of meaningful feedback -- they will receive when nothing is selected in -- the Finder. if length of theList is 0 then display dialog "There are no items in the Finder selection. Select some items in the Finder and try again." end if -- return the new list return theListend getfinderselection</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/EmbededAppleScripts/listing1.html%3Fid%3DDTS10000664-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/EmbededAppleScripts/listing1.html%3Fid%3DDTS10000664-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/EmbededAppleScripts/listing1.html%3Fid%3DDTS10000664-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>