Re: A newbie's problems with Pages and Applescript
Re: A newbie's problems with Pages and Applescript
- Subject: Re: A newbie's problems with Pages and Applescript
- From: Adam Morris <email@hidden>
- Date: Sun, 31 Oct 2010 11:49:11 +0700
> What's the rick to getting a script to dialogue box and to choose and successfully open the (rtf) text document in Pages that's been selected?
If I understand you correctly I think you want:
set nihaortf to name of info of (choose file)
open nihaortf using app "Pages"
delay 1
Tell app "Pages"
Tell document nihao
Xuexi hao zhongwen!
Sent from my iPad
On Oct 31, 2010, at 3:04 AM, email@hidden wrote:
> Send AppleScript-Users mailing list submissions to
> email@hidden
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.apple.com/mailman/listinfo/applescript-users
> or, via email, send a message with subject or body 'help' to
> email@hidden
>
> You can reach the person managing the list at
> email@hidden
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of AppleScript-Users digest..."
>
>
> Today's Topics:
>
> 1. A newbie's problems with Pages and Applescript
> (alma-services.abel.co.uk)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 29 Oct 2010 22:37:13 +0100
> From: "alma-services.abel.co.uk"
> <email@hidden>
> Subject: A newbie's problems with Pages and Applescript
> To: email@hidden
> Message-ID:
> <email@hidden>
> Content-Type: text/plain; charset="utf-8"
>
> Hello Applescript users,
>
> Let me explain where I'm coming from. I'm studying Mandarin
> Chinese, using the wonderful "Ni Hao" Chinese language course (by Paul
> and Shumang Fredlein, http://www.chinasoft.com.au/). To help with
> vocabulary, I use a program called StudyCard (by Terry Bird, http://www.digitalmeadow.com/)
> . At first, I just entered more vocab into StudyCard, in little dribs
> and drabs, as I progressed through the chapters of the first book for
> Ni Hao. But after a while, it just became too many Chinese characters
> to easily enter and format (font size, card layout and colour).
>
> So after a while I got intrigued by applescript. I messed around
> with it and came up with something that does the formatting of my
> study cards automatically, from a tab delimited RTF text file. My
> script is a bit flakey, and only fit for my own use right now. My
> problem is I don't know how to get the script to be user-friendly and
> open a file that the user chooses, from a dialogue. Instead, when the
> script runs, it assumes that the file is already open in Pages, and
> called "NiHao Raw.pages". Right now, everything falls over if it's
> not there when you click on run. What's the rick to getting a script
> to dialogue box and to choose and successfully open the (rtf) text
> document in Pages that's been selected?
>
> So here's the whole script, below. (The big 'tell document "New
> NiHao"' block does the meat and potatoes of the formatting, and is
> irrelevant my choosing-an-input-file problem. I include it to give you
> the whole picture. And because I worked _really_ hard on getting the
> damn formatting right for doing my study cards on my little Palm Z22!
> Profesh...)
>
> -- FILE STARTS: "NiHaoFormat.Test" --
>
> local the_paragraphs, theParts
> set theParts to {}
>
> -- closeAnnoyingDialog(application "Pages")
>
> tell application "Pages"
>
> (*
> set theFile to (choose file with prompt "Choose the Ni Hao vocabulary
> file:" without invisibles)
> set fileName to name of (info for theFile)
> -- set theDocument to document fileName
> open theFile
>
> tell document fileName
> set the_paragraphs to paragraphs of body text
> end tell
> *)
>
> -- the "NiHao Raw.pages" input file should be open in Pages when
> running this script...
> tell document "NiHao Raw.pages"
> set the_paragraphs to paragraphs of body text
> end tell
>
> set n to count of the_paragraphs
>
> -- output file for you to rename and save...
> make new document at front with properties {name:"New NiHao",
> template name:"NiHao"}
>
> tell document "New NiHao"
> tell body text
> repeat with p from 1 to n
> set theParts to my split(item p of the_paragraphs, tab)
> set theCount to count theParts
>
> if theCount is greater than 0 then
> set theChineseCharacters to (item 1 of theParts)
> set countOfCharacters to (count theChineseCharacters)
>
> if countOfCharacters = 1 then
> make new text at end with data (theChineseCharacters) with
> properties {character style:"Ch1"}
> else if countOfCharacters = 2 then
> make new text at end with data (theChineseCharacters) with
> properties {character style:"Ch2"}
> else if countOfCharacters = 3 then
> make new text at end with data (theChineseCharacters) with
> properties {character style:"Ch3"}
> else if countOfCharacters = 4 then
> make new text at end with data (theChineseCharacters) with
> properties {character style:"Ch4"}
> else if countOfCharacters ≥ 5 then
> make new text at end with data (theChineseCharacters) with
> properties {character style:"Ch phrase"}
> else
> -- zero chars then don't do anything
> end if
> end if
>
> if theCount is greater than 1 then
> make new text at end with data (tab & item 2 of theParts) with
> properties {character style:"pinyin"}
> end if
> if theCount is greater than 2 then
> make new text at end with data (tab & item 3 of theParts) with
> properties {character style:"English Meaning"}
> end if
> if theCount is greater than 3 then
> make new text at end with data (" " & item 4 of theParts) with
> properties {character style:"pinyin-meaning"}
> end if
>
> -- not needed: make new text at end with data (return)
> end repeat
> end tell
> end tell
> end tell
>
> on split(t, d)
> local L
> set AppleScript's text item delimiters to d
> set L to text items of t
> set AppleScript's text item delimiters to ""
> return L
> end split
>
>
> (* closeAnnoyingDialog should close the annoying dialog that iWork 2008
> * applications present when no document is open
> *)
> on closeAnnoyingDialog(theApplication)
> try
> set hasWindow to document of window 1 of theApplication
> hasWindow
> on error
> return
> end try
> try
> set firstWindowDoc to path of document of window 1 of theApplication
> firstWindowDoc
> on error
> tell theApplication to close window 1
> end try
> end closeAnnoyingDialog
>
> -- FILE ENDS "NiHaoFormat.Test" --
>
>
> Sandy
>
> --
> Alexander Anderson <email@hidden>
> North Yorkshire, England
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://lists.apple.com/mailman/private/applescript-users/attachments/20101029/f87fc69c/attachment.html
>
> ------------------------------
>
> _______________________________________________
> AppleScript-Users mailing list
> email@hidden
> http://lists.apple.com/mailman/listinfo/applescript-users
>
> End of AppleScript-Users Digest, Vol 7, Issue 536
> *************************************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden