AppleScript - help for a complete novice

I have used one of the Applescript examples to create an email and modified this so that it fills in the theAddress, theSubject and the first part of theBody automatically. I would now like to be able to add additional blocks/paragraphs of text to theBody using a dialog box from which I could pick a number of blocks of text from 1 to say 20. I have these blocks of text in a TextEdit file and I assume these blocks need to be identified/named in some way using AppleScript so that a list can be created and put into a Dialog box.


I have no programming experience and have looked at the AppleScript Language guide but I still am unable to work out how to do this.

Can someone help me with this?

iMac, OS X Mavericks (10.9.5)

Posted on Mar 1, 2016 5:25 AM

Reply
2 replies

Mar 2, 2016 3:58 PM in response to jashook

jashook wrote:


I could pick a number of blocks of text from 1 to say 20. I have these blocks of text in a TextEdit file and I assume these blocks need to be identified/named in some way using AppleScript so that a list can be created and put into a Dialog box.


If you mark your blocks like this (a label followed by a colon):


User uploaded file

Then code like below will you could display a list that looks like this (command-click for multiple selections):

User uploaded file


With this result:


User uploaded file

SG



tell application "Finder"

set f to (choose file) as alias

set p to (read f as «class utf8»)'s paragraphs

set b to choose from listpwith prompt "Choose 1 or more blocks:" with multiple selections allowed

if result is false then return

end tell


set myBlocks to ""

repeat with i in b's items

set myBlocks to myBlocks & (i as text)'s text ((offset of ":" in (i as text)) + 2) thru -1 & return

end repeat


return myBlocks

Mar 9, 2016 3:03 AM in response to SGIII

Thank you very much for your help. Your example didn't quite work on my system. I was able to select the TEXT file but the dialog box did not return a list but the Block text buried within other characters. So I tried putting the the text into the script (see below) and that worked perfectly (probably not the most elegant solution).


seta

seta

set a to "Alpha1: First sentence of required text. Second sentence."

set b to "Beta2: First sentence of required text. Second sentence."

setcto "Delta3: First sentence of required text. Second sentence."

setpto {a, b, c}

set b to choose from listpwith prompt "Choose 1 or more blocks:" with multiple selections allowed

if result is false then return



set myBlocks to ""

repeat with i in b's items

set myBlocks to myBlocks & (i as text)'s text ((offset of ":" in (i as text)) + 2) thru -1 & return

end repeat


return myBlocks

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript - help for a complete novice

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.