OCInkjet.com 728x90 banner, image is updated by season.

Apple-AppleScript-Script-Editor-Logo

Shop HP Download Store and get $5 OFF Orders Over $50! Use Promo Code SPEND150SAVE15

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.
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

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 Info Window Data to Write Scripts

apple1 1244596i 300x210

In the initial section of this post, I leave the AppleScript code formatted as it would appear in the Script Editor pane to show that keywords, statements and other expressions that appear in blue in the Script Editor are part of the AppleScript language and syntax and knowing that is helpful when writing scripts.

Let’s start with this statement:

set theFile to choose file with prompt “Please select a file:”
set fileInfo to info for theFile

The first statement get the full path to a document, in this case, “My Document.cwk” and the second, all of the information on the document:

{name:”My Document.cwk”, creation date:date “Monday, June 8, 2009 8:24:34 AM”, modification date:date “Monday, June 8, 2009 8:24:34 AM”, icon position:{0, 0}, size:1.9715E+4, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:”cwk”, displayed name:”My Document.cwk”, default application:alias “Macintosh HD:Applications:AppleWorks 6:AppleWorks 6.app:”, kind:”com.apple.appleworks.document”, file type:”CWWP”, file creator:”BOBO”, type identifier:”com.apple.appleworks.cwk”, locked:false, busy status:false, short version:”", long version:”"}

This all looks pretty intense, but some of the info is only relevant for certain types of files (folders as opposed to documents, for instance) and although Applescript will return info in the form of an empty string or ‘false’ on some items, the info is usually of little use unless you are targeting the right file type.

With that in mind, let’s look at some of the results that are relevant for the file “My Document.cwk” which is an AppleWorks Document:

Creation Date:

set filedate to creation date of (info for theFile) result–> date “Monday, June 8, 2009 8:24:34 AM”

Modification Date:

set fileModDate to modification date of (info for theFile) result–> date “Friday, July 17, 2009 10:48:20 PM”

File Size:

set fileSize to size of (info for theFile) result–> 1.9715E+4

Miscellaneous Info:

set isFolder to folder of (info for theFile)
set isAlias to alias of (info for theFile)
set isPackage to package folder of (info for theFile)
set isVisible to visible of (info for theFile)
set extHidden to extension hidden of (info for theFile)
set fileLocked to locked of (info for theFile)
–all of these return a boolean (true or false) value and some are only relevant when the target is a folder.


The following, I find the most useful for what I usually need to do:

set extName to name extension of (info for theFile) –> result: “cwk”

set displayName to displayed name of (info for theFile) –> result: “My Document.cwk”

set defaultApp to default application of (info for theFile) –> result: alias “Macintosh HD:Applications:AppleWorks 6:AppleWorks 6.app:”

set fileKind to kind of (info for theFile) –> result: “com.apple.appleworks.document”

set fileType to file type of (info for theFile) –> result: “CWWP”

set fileCreator to file creator of (info for theFile) –> result: “BOBO”


set fileTypeIdentifier to type identifier of (info for theFile)
–> result: “com.apple.appleworks.cwk”

Just something to note on a similar subject:

short version of (info for theFile) and long version of (info for theFile) are mainly only relevant for applications such as this case with AppleWorks 6:

“AppleWorks 6.2.4 for Mac OS X Copyright Apple Computer, Inc. 1991-2002″ –> the long version of AppleWorks 6

If you get the info for a file and place it into a variable, then you can use that to simplify and extract specific items of the info variable and place them into their own specifice variables such as this one using our original document:

set theFile to choose file with prompt "Please select a file:"
set fileInfo to (info for theFile)
set fileDate to creation date of fileInfo

Here’s an ‘all purpose’ script to open a document. It gives you some idea of how you can use data from a documents ‘Get Info’ window. What is shown here will work with most documents, provided you have the application on your desktop.

set theFile to choose file with prompt "Please select the file you want to open:"
set fileInfo to info for theFile
set theFile to theFile as alias
set defaultString to ((default application of fileInfo) as string)
set AppleScript's text item delimiters to ":"
set AppString to (text item -2 of defaultString)
set AppleScript's text item delimiters to "."
set theApp to (text item -2 of AppString)
openDoc(theFile, theApp)
on openDoc(fileName, defaultApp)
tell application defaultApp
activate
open fileName
end tell
end openDoc

Contact me if you have any questions or comments at: hyperscripter@gmail.com or http://twitter.com/hyperscripter.

tech fav 1

101 comments to Using Info Window Data to Write Scripts

  • Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your site? My website is in the exact same area of interest as yours and my visitors would definitely benefit from some of the information you present here. Please let me know if this okay with you. Thanks a lot!

  • I simply want to say I am just very new to blogging and definitely savored this blog. More than likely I’m going to bookmark your blog post . You absolutely come with incredible article content. Many thanks for revealing your blog.

  • Very easily, your content is in fact by far the most practical for this valuable area. To be sure using all ones studies and definitely will desperately expect to have your impending messages. Declaring appreciate it won’t only do, for that fantasti k lucidity in your publishing. I’m going to direct try to find your current feed to have well informed of your changes. Reliable get the job done and far achievements inside your business deals. Take care,

  • Thank you for sharing your ideas about this. Keep it up!

  • There is absolutely simply better way to spruce up your kitchen area than with a bar along with a handful of fabulous looking bar stools. Never forget that the bar stools are actually what will set it all off.

  • Paintball has got to be one of the most pleasurable and exciting games to play that I’ve ever experienced. There’s a really good reason why it is getting so popular. If you have not tried it , then you should give it a go.

  • Thanks, You probably haven’t purported to do this, however I believe you could have could express the mind-set that lots of patients are really in.

  • Congratulations on having essentially the most luxurious community forums Ive come upon in some moment in time! Its just incredible simply how much you could reduces from another thing just because of how visually lovely it really is. Youve compiled an excellent blog house –great image, video clips, describe. This is definitely a must-see blog!

  • Someone unavoidably help to construct brutally blog posts I’d state. This is certainly the really most importantly time I frequented your online site site thus far? I shocked using the analysis individuals fabricated to create this approach certain put up magnificent. Shining method!

  • It a new idea! Just wanna say thank you for your information you encounter posted. Just continue composing one of these post. I am about to a loyal reader, thanks a lot.

  • Thanks, You probably haven’t supposed to do this, however I believe you have managed to express the mind-set that many of individuals are really in.

  • My hope is the idea that some participants in our community will probably be attracted to shared their scholarly work for possible presentation along at the conference.

  • I love what you guys are up too. Such clever work and coverage! Keep up the awesome works guys I’ve included you guys to our blogroll.

  • I like what you guys tend to be up too. This kind of clever work and exposure! Keep up the amazing works guys I’ve included you guys to my personal blogroll.

  • My cousin instructed I accidentally might like this website. He seemed to be entirely right. This post genuinely made my day. You cannot imagine simply how much time frame I had developed depleted because of this information! Merit

  • My hope is because some participants in our community will be attracted to submitting their scholarly get a job with possible presentation along at the conference.

  • Whilst Twitter is normally used by individuals to be in close reference to buddies and also loved ones folks, it’s a growing number of often getting used simply by companies and organizations in an effort to marketplace items and services. The likes regarding Dell as well as Jet Glowing blue utilize Twitter to market their solutions along with Barack Obama and also John Edwards utilized Twitter being a advertising signifies through the campaign trail.

  • I became some great info here. I do think that if a greater number thought of it that way, they’d have a better time get the hang ofing the difficulty.

  • Thanks, You probably haven’t purported to achieve this, however I believe you have got was able to express the mind-set that many of individuals are in.

  • I am really fanatic of your respective blog…will get answered adequately asap. I’m really happy along with your specific writing skills and likewise with the layout on your web site. Is this a paid theme or did you customise it by yourself? Anyway maintain the nice high quality writing, it’s infrequent to ascertain a beautiful weblog of this nature 1 today..

Leave a Reply

  

  

  

HTML Guide from Peachpit Press

$1.99 Web Hosting at Go Daddy 120x240
Apple-Computer-Sticker-Old

iPhoto 6

Apple-ID-Badge
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"}

AppleScript 1-2-3

Stop by every day to shop our new Deal of the Day at BarnesandNoble.com!

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