>
Apple-AppleScript-Script-Editor-Logo

Basic AppleScript Dialog:

display dialog "Your text here" with icon stop buttons {"OK"} default button {"OK"} giving up after 5

'giving up after 5' will automatically close the script after the indicated interval of time has elapsed.

HTML Anchor Code

Here is a sample of how to write code to link one part of your blog page to another:

<a name = "By Email">[optional text]</a> --place this where you want the link to go <a href = "#By Email">By Email</a> --this is the actual link

more HTML

HTML Code to Link to Other Web Pages

Here is a sample of code to link to another page. this is similar to the anchor code, except that the destination code is the url of the destination site:

<a href= "www.webSite.
com"> Website Name</a>

--just replace "www.webSite.
com"
with the actual url destination site and replace 'Website Name' with the prompt that the user will see.

My Links

Apple-IIc-Apple-Screen

AppleScript Note:

It might be interesting to those of you who are AppleScript enthusiasts that the HyperCard (HyperTalk) project was the prototype back in the '80's of what became the system-wide Applescript language (akin to JavaScript) that is in use today.
Apple-Mac-512-Screen
3d-iMac-Large

Trapping for List Dialog Errors

With 'List Dialog' type dialogs, since errors cannot be intercepted in an 'on error' handler, there is no 'normal' way to trap for 'Cancel' which, of course, would result in some sort of undesirable error dialog such as 'User cancelled. Error number -128'. Here is an example of one simple way I have found to trap for this type of error: set x to (choose from list {"Joe","Amy",
"Bill"} with prompt "Choose a record:")
if x is false then
else
set targetItem to (x as text)
show every record whose cell "Name" contains x
end if
When the user clicks on 'Cancel', the variable x is assigned the boolean value false. So all you have to do is set up a conditional to deal with that and to perform the usual statements otherwise.

Learning AppleScript

AppleScript-123-Book

Create Multiple Folders with Terminal

If you are more of a techy kind of person and are comfortable with using Terminal, here is a script you can use to easily create multiple folders:

First, for a single folder, type in: mkdir "Folder 1" --or whatever you want to name your folder, this creates a new directory, which, in effect is a new folder. To place multiple items in the 'Documents' folder: cd/Users/Administrator/Documents mkdir "Folder 1" "Folder 2" "Folder 3" To quickly create multiple folders, create a text file with the desired folder names (as many as you want) and name it something like 'folderList.txt'. Next type this in Terminal: cat folderList.txt |xargs mkdir Or you could create folders with the same prefix by entering: mkdir "Invoices " {"Corporate", "Individual", "Pro-Bono"}

Digg! Digg This!!

Mac LC III (1994), the first Mac that I ever owned, the CD-Rom and Zip drive were added much later.

Mac LC III (1994), the first Mac that I ever owned, the CD-Rom and Zip drive were added much later.

Basic HTML

Here is an example of a very simple HTML document:

<html>
<head>
<title>Basic HTML Document</title>
</head>
<body>
Your text goes here
</body>
</html>

more HTML

AppleScript Definitions

AppleScript Icon Black Background

AppleScript

Although you can get basic info on how to script a particular application and the Finder itself from its AppleScript Dictionary, I find that all too often the descriptions given are lacking. That is why I have included my own dictionary here to clarify. However, if you would like to see an specific dictionary, all you have to do is open the Script Editor and choose “Open Dictionary…” from its File Menu and choose the application from the dialog.


A B C D E F G H I J K L M N O P Q R S T U V W X Y Z


Tips on Reading and Understanding AppleScript Dictionaries

Before you Get Started, I Highly Recommend that you Take a Quick Look at these Comments on Dictionaries

An entry taken from the AppleWorks 6 Dictionary:

make v : Make a new element
make
new type : the class of the new element.
at location specifier : the location at which to insert the element
[with data any] : the initial data for the element
[with properties record] : the initial values for the properties of the element
–> specifier : to the new object(s)

Some things to note about dictionary entries

1) The first line, make v : Make a new element, is the basic definition of the term

2) The second item in the first line in italics (v here) describes the term as an English part of speech, here, a verb. This is significant, because AppleScript is written basically like sentences in English.

3) Text in bold is to be written literally

4) All plain text is not to be taken literally and is a description of the element or term in bold.

5) Text within straight brackets are optional parameters that may not apply for what you want to do.

6) Blue, underlined text is a link to a further definition of the term or attribute.

In the ‘make’ example above (omitting optional stuff), you could say:

make new document at desktop

Alias – A MacOS path reference to the location of a file or folder. Something like: alias “Macintosh HD:Users:administrator:Documents:”

Block – Instructions or statements that are grouped together such as tell application “Finder” … end tell or repeat … end repeat etc.

Conditional – A group of optional instructions where the user must make a choice, for instance: if clientName is “Bill” then … else if clientName is “Betty” … else … end if etc.

Current Date – Returns something of the form: date “Sunday, June 14, 2009 8:05:31 PM”. To extract just the date from ‘current date’ say: date string of (current date). Results in: “Sunday, June 14, 2009″

File Type – Represents a four character code that identifies the kind of document, for example: “CWWP” – an AppleWorks 6 text document.

Front Finder Window – The currently active, visible window. In the hierarchy of open windows, this is the window at the very front. It has a reference of 1, it can be referred to as finder window 1

Offset – Identifies the numerical position of a specified text character within a specified text string, as in (the offset of “i” in “Bill”, which would return 2 since ‘i’ is the second character found in “Bill”.

Path – Get location of a file or folder on your computer, as in: path to desktop – results in something of the form of: alias “Macintosh HD:Users:administrator:Desktop:”

POSIX Path – POSIX stands for Portable operating System for UNIX. A POSIX path gives a UNIX path reference to a file or folder.

Property – A sort of variable that typically sets initial values for a document, for instance in AppleWorks 6 it usually takes this form: properties {name:”Document 1″}

Result – A sort of temporary variable that ‘results’ from a script execution such as a dialog. Actually, the result is a record containing bits of information separated by commas that can be saved in variables for further script execution.

Selection – The object which has just been selected, such as in: select paragraph 1, It can be just about anything that you would be able to select to move, delete, duplicate etc.

Tell – The Tell command directs a statement or block of statements to a specific object, most commonly an application, as in ‘tell application “Finder” to activate’ or ‘tell front document to select paragraph 1′
.

Text Item Delimiters – A keyboard character usually a comma or other punctuation, used to separate different pieces of data. Full synyax is something of the form ’set AppleScript’s text item delimiters to “,”‘. Often in lists or records such as {”Peter”,”Paul”,”Mary”}. Here, if a comma is used, text item 2 would be “Paul”.

Try – The Try statement asks the target to attempt to execute a statement or group of statements. If an error occurs, it is intercepted and another course of action may be invoked. Full syntax: try…statement(s)…on error…error handler…end try.

Variable – A container which holds a value, which is usually assigned with ’set’ or ‘copy’


A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Back to Top

Favorite this site:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogosphere News
  • Live
  • StumbleUpon
  • Technorati
  • TwitThis
  • Yahoo! Buzz
  • MySpace
  • YahooMyWeb
  • HackerNews
  • RSS
  • Twitter
  • E-mail this story to a friend!
  • Internetmedia
  • Webnews.de
  • Yahoo! Bookmarks
Apple-ID-Badge

Apple-Computer-Sticker-Old
Create Multiple Folders with Terminal

If you are more of a techy kind of person and are comfortable with using Terminal, here is a script you can use to easily create multiple folders:

First, for a single folder, type in: mkdir "Folder 1" --or whatever you want to name your folder, this creates a new directory, which, in effect is a new folder. To place multiple items in the 'Documents' folder: cd/Users/Administrator/Documents mkdir "Folder 1" "Folder 2" "Folder 3" To quickly create multiple folders, create a text file with the desired folder names (as many as you want) and name it something like 'folderList.txt'. Next type this in Terminal: cat folderList.txt |xargs mkdir Or you could create folders with the same prefix by entering: mkdir "Invoices " {"Corporate", "Individual", "Pro-Bono"}

Add http://www.scriptsforapple.com to Technorati Favorites

Apple-iMac-Rainbow

Digg! Digg This!!

An AppleScript to Verify a Date

Run this in the Script Editor:

set dateRecord to (current date)
set defaultDate to (date string of dateRecord)
try
set apptDate to text returned of (display dialog "Enter appointment date:" default answer defaultDate buttons {"Set"} default button {"Set"})
set datetext to apptDate as text
date apptDate --if an invalid date is entered, the next dialog is aborted and it triggers the error alert below.
display dialog datetext & " is a valid date." with icon note buttons {"OK"} default button {"OK"}
on error
set alertText to "An error has occurred!"
set messageText to quote & datetext & quote & " is an invalid date."
display alert alertText message messageText as warning buttons {"OK"} default button "OK" giving up after 15
return
end try

Airport-Extreme-Hardware