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

An AppleScript for iTunes Playlists

Apple iTunes Music Notes1Here is a simple AppleScript for iTunes which chooses a pre-determined playlist from your iTunes library, then prompts for the volume level. After all of this is done, it plays the selected playlist at the specified volume level:

tell application "iTunes"
activate
set visible of front window to true
set view of front window to playlist "Hall & Oates"
copy (get view of front window) to thePlaylist
set soundValue to (choose from list {"25", "50", "75", "100"} with prompt "Select volume level:" OK button name "Play" cancel button name "Abort")
set soundValue to soundValue as integer
set sound volume to soundValue
play thePlaylist
end tell


The line
‘copy (get view of front window) to thePlaylist’ assigns, in this case, “Hall & Oates” to the variable thePlaylist (the name assigned must be the actual name of an existing playlist). The second important thing to note here: set soundValue to soundValue as integer. This is required because the list dialog returns a text value, so we must coerce the value to integer.

There is one problem with this script. If we click on the ‘Abort’ button the playlist is still played. This problem can be handled with a conditional which will ‘trap’ for this such as: if soundValue is not “false” then play thePlaylist.

An enhancement of the above script:

tell application "iTunes"
activate
set visible of front window to true
set thePlaylist to (choose from list {"Hall & Oates", "Aja", "Elton John", "ELO"} with prompt "Select a playlist:" OK button name "Choose" cancel button name "Abort") as text
if thePlaylist is not "false" then
set view of front window to playlist thePlaylist
copy (get view of front window) to thePlaylist
set soundValue to (choose from list {0, 25, 50, 75, 100} with prompt "Select volume level (0 for mute):" OK button name "Play" cancel button name "Abort")
if soundValue is not "false" then
set sound volume to soundValue
play thePlaylist
end if
end if
end tell

In this second script we use a choose list command to get the playlist we will use. Also in this script, we assign names to the button choices: OK button name “Play” cancel button name “Abort”

Finally, we use 0 for when we want to make the sound mute:
{0, 25, 50, 75, 100} and since the number list items are not enclosed in quotes, AppleScript does not need to coerce the chosen value to integer.

If you wanted to get all of your playlists to appear in a choose from list dialog it would go something like this:

set thePlaylists to (name of every playlist)
set thePlaylist to (choose from list thePlaylists with prompt "Select a playlist:" OK button name "Choose" cancel button name "Abort") as text

If you have further questions on scripting with iTunes or would like to suggest a post on another AppleScript issue, 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


94 comments to An AppleScript for iTunes Playlists

  • Best wishes on having one of the most state-of-the-art community forums Ive stumble upon in some time period! Its just amazing simply how much you can gets rid of from one thing because of precisely how to the eye gorgeous it really is. Youve compiled a good website area –great visuals, video clips, blueprint. This is definitely a must-see weblog!

  • I am really fan of your respective blog…will get found the key to competently asap. I’m really impressed in addition to your specific writing competencies and also with all the describe on your own site. Is the a paid for issue or perhaps you customize it ones self? Anyway carry on the excellent fine quality composing, it’s rare to work out an amazing website of this nature 1 today..

  • Many thanks your marvelous blog submitting! I critically enjoyed analyzing it, you happen to be a good writer.I shall confirm that I bookmark your website and shall get back in the foreseeable time to come. I want to promote continue your particular great position, have got a nice day time!

  • I delight in, cause I found just what I was taking a look for. You have ended my four day lengthy hunt! God Bless you man. Have a great day. Bye

  • AKO

    Thank you very much for posting this post. It has benifited me and my dad hundreds and I doubtless browing by way your other posts as I enjoyed this publish very much. Thanks once more and proceed the great work!

  • A person essentially lend a hand to make severely posts I might state. That is the first time I frequented your web page and to this point? I amazed with the research you made to make this actual publish incredible. Great activity!

  • Pretty component to content. I just stumbled upon your weblog and in accession capital to say that I get actually loved account your weblog posts. Any way I’ll be subscribing on your feeds and even I fulfillment you get admission to consistently quickly.

  • I will right away grab your rss feed as I can not to find your email subscription hyperlink or e-newsletter service. Do you have any? Please allow me realize so that I could subscribe. Thanks.

  • F*ckin? tremendous things here. I?m very glad to peer your article. Thank you a lot and i’m looking forward to touch you. Will you kindly drop me a e-mail?

  • You’re truly a excellent webmaster. The web site loading pace is amazing. It kind of feels that you are doing any unique trick. In addition, The contents are masterpiece. you have done a fantastic job in this topic!

  • Thank you, I have recently been searching for info approximately this topic for a long time and yours is the best I have came upon so far. However, what about the bottom line? Are you sure in regards to the source?

  • wonderful publish, very informative. I’m wondering why the other experts of this sector don’t understand this. You should continue your writing. I am sure, you’ve a great readers’ base already!

  • I have been browsing on-line more than 3 hours nowadays, yet I by no means found any attention-grabbing article like yours. It?s pretty price enough for me. In my view, if all web owners and bloggers made excellent content material as you probably did, the internet might be much more useful than ever before.

  • I see articles online all the time and some are quite interesting. Since I’ve written quite a few articles myself, and even published a few books, it could be helpful for me to get my name out there by presenting my articles. How would I go about putting them online for everyone to access, and could I make money posting them? This may be a silly question but, do people generally seek copyright for their online articles? Thanks..

  • I be familiar with your blog all the metre and I at best thought I’d state mind up the decorous cultivate!

  • Paintball has become one of the most fun and adventurous games to play that I’ve ever seen. There is a good reason why it is getting so popular. If you have not tried it yet, then you are really missing out.

  • I happen to enter your blog with the help of google search. To my sheer luck I got what I was searching for. Thanks
    regards
    lodaz

  • Definitely, what magnificent weblog and instructive topics, I undoubtedly will bookmark your internet site.All the Best!

  • We’re really fan of your blog…will get found the key to competently as soon as possible. I’m really fulfilled together with your specific composing capabilities and also together with the layout on your web log. Is that this a paid for masquerade or perhaps you customize it yourself? Anyway maintain the beneficial top quality text, it’s sparse to determine a wonderful weblog similar 1 these days..

  • I became some great info here. I feel if a greater number thought about it that way, they’d possess a better time obtain the hang ofing the situation.

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