>
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

Using FileMaker Pro

FileMaker Pro 6 SoftwareFor those of you who are new to FileMaker and have done other types of scripting, this will be somewhat foreign. As with AppleScript, though, I will deal with FileMaker-specific scripts in the same step-by-step manner. If you are an AppleScript enthusiast, as I am, you will be glad to know that most of what I present in these posts will include some applescripting.

Find Request FM Pro 6 | Find Request FM Pro 9 | Password-Protect FM Records
| Create a New Record
| Alphabetical List Dialog of Records
| Custom Dialog
| Show Message Dialog

The world of FileMaker is quite different than what you may be used to if you use a Mac (I know it was, and still is, for me). With that said, let’s take a look at these scripts:


Find Request Script for FileMaker Pro 6:

FileMaker Pro 6 Splash

A script where user enters search text in desired fields and initiates search by hitting the enter key.

The script shows basics of using FileMaker dialogs and handling errors using conditional clauses. This script is specific to FileMaker 6. A script serving the same purpose for FileMaker Pro 9 appears below.

Sort [Restore, No Dialog]
Show Message ["Enter search criteria in
available fields, then hit the 'Enter'
key for result"]
Set Error Capture [On]
Enter Find Mode [Restore, Pause]
Perform Find [Replace found Set]
If ("Status(CurrentError) > 0")
Show Custom Dialog ["Error: 'No
records found.'", No records were
found. Click OK to modify your
request or click Cancel to return
to Browse mode.]
If ("Status(CurrentMessageChoice)
= 1")
Modify Last Find
Else
Enter Browse Mode []
Show All Records
Sort [Restore, No dialog]
End If
Show All Records
Sort [Restore, No dialog]
End If

Add to Technorati Favorites

Contact me at hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.


Find Request Script for FileMaker Pro 9

FileMaker Pro 9 Advanced

This is a script that allows the user to perform a search. It shows how to handle the ‘not found’ error and using the get keyword to retrieve a result value and to handle the result of the find request.

This script uses FileMaker scripting exclusively. Here is how it would appear in the ScriptMaker Window:

Set Error Capture [On]
Perform Find [Restore]
If [Get (LastError) > 0]
Show Custom Dialog ["No records found. Click OK to modify
your request or Cancel for Browse mode."]
If [Get (LastMessageChoice) = 1]
Modify Last Find
Else
Enter Browse Mode []
End If
End If

120x20 su blue

Set Error Capture [On] – this tells FileMaker to capture the value (true or false, ie boolean) of whether or not script execution was successful. 0 is false, 1 is true – see ‘[Get (LastError) > 0]‘ below:

[Get (LastError) > 0] – tells FileMaker that, if no records were found that a ‘not found’ error has occurred

[Get (LastMessageChoice) = 1] -tells FileMaker that if the user chooses the ‘OK’ button to allow the user to attempt another find.

Contact me with any questions or comments you may have and I will be glad to help (where I can): hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.


AppleScript to Password-Protect FileMaker Records

FileMaker Pro 10 Database RecordCreate a global field named ‘accessPass’ to store your password.

Create a script in the ScriptMaker named “Password…” or something similar to place a password in the global field ‘accessPass’, with the following ‘Perform AppleScript’ script step:

set data of of cell "accessPass" to text returned of (display dialog "Please enter a global password:" default answer "" buttons {"OK"} default button {"OK"})

Assign this script to a button such as ‘Delete…’ or whatever name you like:

120x20 su blue

tell application "FileMaker Pro"
try
set recordName to (get cell "Name" of current record)
set purgeRecord to text returned of (display dialog "Please enter password to remove this record:" with icon caution default answer "" buttons {"Delete","Cancel"} default button {"Cancel"} giving up after 10)
set passText to (get cell "accessPass" of current record) as text
if purgeRecord=passText then
set theRecord to (get ID of current record) as integer
set confirmPurge to button returned of (display dialog "Are you sure you want to delete record '" & recordName & "' ?" with icon stop buttons {"Delete","Cancel"} default button {"Cancel"} giving up after 10)
if confirmPurge="Delete" then
delete record ID theRecord
end if
end if
on error
return
end try
end tell

Questions or comments are always welcome. Contact me at hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.


A Script to Create a New Record

Apple Mac Cube and Monitor

This is a script, which combines FileMaker Pro script steps with some AppleScript Code statements. This script assumes that you have a database with these cells: Name,Address,City,State,
Zip,Phone, and Email

In the ScriptMaker Window:

Freeze Window
Flush Cache to Disk
Perform Script [Sub-scripts,"returnRecordReference"]
New Record/Request

Where returnRecordReference is an AppleScript:

In the AppleScript Window:

try
set newRecordReference to (ID of current record)
set data of cell "globalReturn" to newRecordReference
–A global cell to store the ID of the current record before we create a new one
on error errorMsg
display dialog errorMsg
end try

In the ScriptMaker Window:

Perform AppleScript ["try set newRecord to text returned....] (see below):

In the AppleScript Window:

try
set newRecord to text returned of (display dialog "Enter name reference for new record:" default answer "" with icon note buttons {"Cancel","Done"} default button {"Done"})
set newAddress to text returned of (display dialog "Enter address for new record:" default answer "" with icon note buttons {"Done"} default button {"Done"})
set defaultCityState to button returned of (display dialog "Set city and state to 'Columbus, OH' ?" buttons {"Other...","OK"} default button {"OK"})

–Change this to your default City and State:
if defaultCityState="OK" then
set newCity to "Columbus"
set newState to "OH"
else
set newCity to text returned of (display dialog "Enter city for new record:" default answer "" with icon note buttons {"Done"} default button {"Done"})
set newState to text returned of (display dialog "Enter state for new record:" default answer "" with icon note buttons {"Done"} default button {"Done"})
end if
set newZip to text returned of (display dialog "Enter zip code:" with icon note default answer "00000" buttons {"Done"} default button {"Done"})
end if
set newPhone to text returned of (display dialog "Enter phone number:" default answer "" with icon note buttons {"Done"} default button {"Done"})
set newEmail to text returned of (display dialog "Enter new emails and/or web addresses:" default answer "" with icon note buttons {"Done"} default button {"Done"})
set recordDatalist to {newRecord,newAddress,newCity,newState,
newZip,newPhone,newEmail} as list
set cellList to {"Name","Address","City","State","Zip",
"Phone","Email"} as list
repeat with x from 1 to 7
if not (item x of recordDatalist = "") then set data of cell (item x of cellList) of current record to (item x of recordDatalist)
end repeat
show every record
–this makes sure that no records are omitted
sort layout 0 by field "Name" in order ascending –sort by default layout, in case there is more than one
on error errormsg
display dialog errormsg
end try

You may want to have a button named ‘New…’ for this for convenience. Note that I have placed an ‘on error’ handler in this script. This is useful for catching any typos etc that you may have made while writing your script. I put this in most of my scripts (at least while testing) to be sure that there are no ‘anomalies’.

Questions or comments are always welcome. Contact me at hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.

120x20 su blue

A little scriptlet for formatting fields to upper case:FileMaker Pro ScriptMaker Script to Format Fields to Upper CaseAfter placing the ‘Freeze Window’ script step, enter any number of ‘Replace Contents [No Dialog,"Name","Upper(Name)"]‘ script steps to convert text fields to upper case text (where both instances of Name are replaced with the actual field name that you are using in your database). This is very useful when you forget to hit the Caps Lock key before you start typing.

Add to Technorati Favorites

FileMaker Pro 10 Database Software

Alphabetical List Dialog of Records

A script to list all entries beginning with the same alphbetical character. In this case records beginning with ‘A’. Your ScriptMaker window should have the following script steps (complete Perform AppleScript step shown below):

FileMaker Pro Alpha Pointer 300x135

Type this into the ‘Perform AppleScript’ script step window:

try
sort layout 0 by field "Name" in order ascending
set targetAlpha to "A"
set alphaArray to {}
set alphaArray to (ID of every record whose cell "Name" begins with targetAlpha)
set convertArray to alphaArray
set AppleScript's text item delimiters to return
set arrayCount to count items in convertArray
set convertedArray to {}
repeat with x from 1 to arrayCount
set convertedID to (item x of convertArray as integer)
set convertedArray to convertedArray & convertedID
end repeat
set convertedArrayText to {}
repeat with x from 1 to arrayCount
set convertedName to (get cell "Name" of record ID (item x of convertedArray))
set convertedArrayText to convertedArrayText & convertedName
end repeat

FileMaker Pro 9 Advanced

This will filter out erroneous records:
set filterArrayText to {}
repeat with x from 1 to arrayCount
if (character 1 of word 1 of item x of convertedArrayText = targetAlpha) then set filterArrayText to filterArrayText & (item x of convertedArrayText)
end repeat

set targetRecord to ""
set arrayCount to count text items in filterArrayText
set arrayCount to arrayCount as text
set targetRecord to (choose from list filterArrayText with prompt arrayCount & " search results found for '" & targetAlpha & "':")
show every record whose cell "Name" = targetrecord
on error theError
if theError contains "Object" and targetRecord=false then
else if theError contains "Object" and targetRecord≠false then
display dialog "No items found for: '" & targetAlpha & "' !" with icon stop buttons {"Done"} default button {"Done"} giving up after 5
else
display dialog theError with icon stop buttons {"OK"} default button {"OK"}
end if
end try

Add to Technorati Favorites

The ‘Show All Records’ script steps at the beginning and end could ordinarily be replaced by ’show every record’ within the ‘Perform AppleScript’ script step, but for some unknown reason, I have been unable get this to work that way.

As shown though, this should work without any problems.

cf widget

If you have comments or advice on this or any of my other posts, or would like to suggest another topic, you can contact me at:

hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe,
click the By Email link at the top of the page.


FileMaker Pro 6 Custom Dialog Script

FileMaker Pro 6 ManualThis Script shows how to use FileMaker’s Custom Dialog to write a script with optional text entry fields with the Perform Find Script Step. For this you will first need to create global text fields: ‘gName’, ‘gAddress’, and ‘gPhone’,

Show Custom Dialog ["Find by name, address or phone", "Enter any combination of name, address or phone. Click OK to continue.", "gName"], "gAddress", "gPhone"
If ["Status(CurrentMessageChoice = 2)"]
Exit Script
End if
Enter Find Mode []
If ["not IsEmpty(gName)"]
set field ["Name", "gName"]
End if
If ["not IsEmpty(gAddress)"]
set field ["Address", "gAddress"]
End if
If ["not IsEmpty(gPhone)"]
set field ["Phone", "gPhone"]
End if
Perform Find [Replace Found Set]
If ["Status(CurrentError )= 401"]
Show Message ["Sorry, no records found!"]
Show All Records
set field ["gName", """"]
set field ["gAddress", """"]
set field ["gPhone", """"]
End if

In the first conditional, ‘If ["Status(CurrentMessageChoice = 2)"]‘, we test for the ‘Cancel’ button (value 2) which would end the script ends with no further execution.

After we go to find mode, we enter the text, if any, into the appropriate fields to prepare for our search. Where there is a value entered it is placed in the appropriate field. Note that since we are in find mode, we are not replacing the existing text of the current record.

Contact me if you have any questions or comments at: hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.

Add to Technorati Favorites

FileMaker’s Show Message Dialog

FileMaker Pro 10 BabeThis Post gives you the basics on FileMaker’s ‘Show Message’ dialog and how to handle user feedback based on the button chosen. As you’ll notice from the actual text of the dialog below, clicking on a button returns a numerical value corresponding to the button clicked.

But first, the Show Message Edit Window:FileMaker Pro Show Message Edit

Go to Record/Request/Page [First]
Show Message ["This is a simple dialog with an 'OK' and a 'Cancel' button. OK returns a value of 1 and Cancel, a value of 2."]
If ["Status(CurrentMessageChoice) = 1"]
Go to Record/Request/Page [Next]
Else
Go to Record/Request/Page [By Number...]
End If

The numerical value corresponding to the button clicked, is used by ‘Status(CurrentMessageChoice)’ to determine a course of action. If the user clicks OK (value=1), then it goes to the next record, otherwise you are prompted to enter the record number you want.

120x20 thumb gray

This is the ‘Show Message’ dialog (or sheet):
FileMaker Pro Show Message Sheet

Note: The numerical values of the buttons are right to left, i.e. OK is 1 and Cancel is 2.

If you have comments or need advice on this or any of my other posts, you can contact me at hyperscripter@gmail.com or http://twitter.com/hyperscripter or to subscribe, click the By Email link at the top of the page.

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