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

Concatenation or Parsing and Editing of Text Strings

Xerox Palo Alto 1983In this section we deal with various methods to extract different parts of text from lists and other text and at the end, how to put it all together to make a new text string. This is sort of lengthy, but it is pretty easy to follow,

First, to extract text from a list. Both of these result in the text “Computer”:

set theTextList to {"Apple", "Computer"} as list
last item of theTextList
last text item of theTextList --> both statements yield 'Computer'

And then using the ‘reverse’ keyword:

set theTextList to {"Apple", "Computer", "Inc"} as list
last text item of theTextList --> yields "Inc"
set theTextList to reverse of theTextList --> yields {"Inc", "Computer", "Apple"}
last text item of theTextList --> yields "Apple"

As you can see, the keyword ‘reverse’ changes the order of items in a list.


If we want to extract a specific word:

set theTextString to "Apple Computer, Inc"
set theAppleString to word 1 of theTextString
display dialog theAppleString --> yields "Apple"

If we want to extract a specific paragraph:

set theTextString to "Apple Computer, Inc" & return & "Home of Mac OS X"
set theAppleString to paragraph 2 of theTextString
display dialog theAppleString --> yields "Home of Mac OS X"


Extracting by numerical index:

set theTextString to "Apple Computer"
set computerStringStart to offset of "Computer" in theTextString
display dialog computerStringStart --> yields 7: position of first letter in the word 'Computer'
set computerText to (text computerStringStart thru -1 of theTextString)
display dialog computerText --> yields 'Computer'
-1 is the index for the last letter of the text string, no matter how long the string is; a lot easier than having to determine how long the string is every time!

The same as saying:

set computerText to (text 7 thru -1 of theTextString)
Of course, if we wanted to, we could say:
'set computerText to (text 7 thru 14 of theTextString)' but why?

120x20 thumb gray


set theTextString to "Apple Computer"
set theAppleString to text 7 thru -2 of theTextString
display dialog theAppleString --> yields 'Compute'-2 gets the numeric index of the letter in 'Computer' that is 2 from the end.


set theTextString to "Apple Computer, Inc"
set theAppleString to text 1 thru -1 of theTextString
display dialog theAppleString --> yields: "Apple Computer, Inc"


set theTextString to "Apple Computer, Inc"
set theAppleString to (words 1 thru -1 of theTextString) as text
display dialog theAppleString --> yields "AppleComputerInc"


set AppleScript's text item delimiters to ","
set theTextString to "Apple Computer, Inc"
set theAppleString to (text items 1 thru -2 of theTextString) as text
display dialog theAppleString --> yields "Apple Computer"

The following would give the same result:

set AppleScript's text item delimiters to ","
set theTextString to "Apple Computer, Inc"
set theAppleString to (text item 1 of theTextString) as text
display dialog theAppleString

Why? Because with ‘set AppleScript’s text item delimiters to “,”‘ , what is found before a comma is a text item and what is after a comma is another text item – this can be very useful.

Look at this:

set AppleScript's text item delimiters to " "
set theTextString to "Apple Computer, Inc"
set theAppleString to (text item 1 of theTextString) as text
display dialog theAppleString --> this yields "Apple", because the space determines the value of text items.

set AppleScript's text item delimiters to " "
set theTextString to "Apple Computer, Inc"
set theAppleString to (text item 2 of theTextString) as text
display dialog theAppleString --> this yields "Computer,", because the space determines the value of text items.



tech fav 1

This illustrates how to concatenate some text to display a dialog:

set AppleScript's text item delimiters to " "
set theTextString to "Apple Computer, Inc"
set theAppleString to (text item 1 of theTextString) as text

–> the result is “Apple”, because the space determines the value of text items.

set theComputerString to (text 1 thru -2 of text item 2 of theTextString) as text

–> the result is “Computer”, because the space determines the value of text items and ‘text 1 thru -2′ eliminates the comma.

Now we can put it all together:

set dialogString to "Too bad all " & theComputerString & "'s aren't " & theAppleString & "s!"
display dialog dialogString with icon note buttons {"No Doubt"} default button {"No Doubt"} giving up after 5

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.

435 comments to Concatenation or Parsing and Editing of Text Strings

  • I do believe all the concepts you’ve introduced to your post. They are very convincing and can certainly work. Nonetheless, the posts are very quick for beginners. May you please lengthen them a bit from next time? Thanks for the post.

  • I am personally really fan of your respective blog…will get solved adequately asap. I’m really happy in addition to your text abilties and also together with the blueprint on your own web log. Is that this a paid masquerade or have you personalize it your own? Anyway sustain the beneficial top quality text, it’s uncommon to work out an exquisite blog of this nature the nowadays..

  • Somebody necessarily help to create strictly content I’d form. It is the truly initial time I frequented your web site page website consequently far? I astonished making use of research you fabricated to create this approach certain submit magnificent. Very good procedure!

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

  • The sense of planning to assist, however not figuring out how and the place, are some things a variety of us already went through a.

  • Definitely, exactly what a grand weblog and instructive reviews, I undoubtedly may bookmark your specific website.All the Best!

  • I d been very glad to find this internet site.I really wanted to express my thanks you for this cool read!! I definitely enjoying every portion of it but i have you ever gigs to looking for new stuff from you post.

  • My hope is the idea that some constituents of our community may possibly be interested in submitting their scholarly get a job with possible presentation along at the conference.

  • I had been very happy to locate this site.I wanted to express my thanks you for this cool read!! I finaly enjoying every amount of it and that i have you bookmarked to looking for new stuff from you post.

  • My hope is because some constituents of our community will be curious about shared their scholarly get a job with possible presentation for the conference.

  • My hope is the idea that some participants in our community may possibly be curious about shared their activity styling possible presentation along at the conference.

  • Thanks, You probably haven’t meant to achieve this, however I believe you have managed to express the mind-set that lots of individuals are currently in.

  • Happy to get visiting your blog again, the doll has been weeks most likely for me. Well, this is actually the story that I’ve been waited for so long.

  • My hope is the idea that some members of our community will probably be interested in shared their scholarly styling possible presentation at the conference.

  • I received some great info here. I believe if a greater number of people thought about it like this, they’d have got a better time receive the hang ofing the issue.

  • My hope is because some members of our community will be interested in promoved their activity rendering possible presentation at the conference.

  • Entrusting our online bank your spondulicks, we think the risks. We assume that the bank hastily disappears

    from the buy, and the moneyed forfeited. Is this possible? Certainly not, because the accumulated savings in

    pecuniary institutions of this kredyt dla studentastrain are subject to a mandatory approach of guaranteeing the Bank Promise Fund. They trade the but crumble as stationary banks with alone entire distress (or facility) – lack of access to facilities. Today, Internet banking is offered timber in our banks. Any large-hearted financial institution has in its offer the adeptness to reinforce a bank account via the Internet. The advantages of such a overweight bank, and customers time after time settle upon the convenience, access to the account 24 hours a era and significantly decrease prices as a replacement for services notwithstanding the operation of an Internet account. If anyone has concerns in advance the understructure of an online account, they are unfounded. Adherence to the principal security rules when using online banking makes her safety is maintained at a steep level. Cybercriminals are insecure computers and the naive user. Opportunity into accounts materialize merely as a sequel of phishing looking for your account, which defines the locution phishing. So reagujmy not suspicious e-mails from the bank we use.

    Hindrance us also remember that access to Internet banking is not so easy.

    It protects the multiple stages of authentication. In appendix, log on to the modus operandi requires a purchaser ID

    and password. Then, each bargain proceedings sine qua non be approved lex non scripta ‘common law from rub erase, or watchword of the SMS.

    Banks use newer and more advisedly pledge, because only depends on our vigilance or our resources intention be one

    hundred percent secure.

  • I am really fan of your blog…will get solved accurately as soon as you can. I’m really satisfied along side your copy skills and also with all the blueprint against your web site. Is that this a rewarded graphics or have you customise it by yourself? Anyway sustain the excellent high quality composing, it’s uncommon to see a wonderful weblog like this 1 today..

  • Say thanks lots for giving everyone tremendously marvellous risk to learn to read crucial remarks from here. It’s always so splendid plus full of fun for most people personally and my office companions to look one’s web site at a smallest thrice within a 7 days to see through the new stuff you will have. And also, I’m just always happy of the putting guidelines yourself give. Selected 2 pointers inside this post are extremely essentially the most amazing I’ve ever endured

  • Please, is it possible to PM me and tell me few more thinks about this particularly,

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