Agnes Riley Posted June 12, 2013 Posted June 12, 2013 I have written the following calculated AppleScript: "tell application " & Quote ( "Microsoft Word" ) & ¶ & "activate" & ¶ & "open" & Quote ( "Macintosh HD:Users:Shared:Guild_Word_Template.dotx") & ¶ & "set theDate to current date" & ¶ & "set text of active document to theDate as text" & ¶ & "save as active document file name " & Quote ( UIN_FOCUS::GT_WORD_FILE_NAME ) & ¶ & "end tell" & ¶ & "tell application " & Quote ( "System Events" ) & ¶ & "tell process " & Quote ( "Microsoft Word" ) & ¶ & "keystroke " & Quote ( "v" ) & " using {command down}" & ¶ & "set theRange to (create range active document start 0 end 23)" & ¶ & "end tell" & ¶ & "end tell" I have a problem with the line that starts "set theRange". I actually have two more lines after this that I've tested in Script Editor irreverent from FM and they work as expected. If I remove this line in FM my script works well. Any idea what's wrong with this line? Thanks, Agi
bruceR Posted June 12, 2013 Posted June 12, 2013 Couple of things. There is no space after Open. I much prefer setting a variable to the script contents; then just perform applescript, calculated, $script I like to do substitutions into the script text. This way you can view and manipulate the contents of $script while testing. Set Variable [ $sourcedoc; Value:"Macintosh HD:Users:Shared:Guild_Word_Template.dotx" ] Set Variable [ $targetdoc; Value: UIN_FOCUS::GT_WORD_FILE_NAME ] Set Variable [ $script; Value: List( "tell application " & Quote ( "Microsoft Word" ) ; "activate" ; "open " & Quote ( $sourcedoc ) ; "set theDate to current date" ; "set text of active document to theDate as text" ; "save as active document file name " & Quote ( $targetdoc ) ; "end tell" ; "tell application " & Quote ( "System Events" ) ; "tell process " & Quote ( "Microsoft Word" ) ; "keystroke " & Quote ( "v" ) & " using {command down}" ; "create range active document start 0 end 23"; "set theRange to result"; "end tell" ; "end tell" ) ] Perform AppleScript [ Calculated AppleScript: $script ]
bruceR Posted June 12, 2013 Posted June 12, 2013 The script might need to be more like this: List( "tell application " & Quote ( "Microsoft Word" ) ; "activate" ; "open " & Quote ( $sourcedoc ) ; "set theDate to current date" ; "set text of active document to theDate as text" ; "save as active document file name " & Quote ( $targetdoc ) ; "end tell" ; "tell application " & Quote ( "System Events" ) ; "tell process " & Quote ( "Microsoft Word" ) ; "keystroke " & Quote ( "v" ) & " using {command down}" ; "end tell"; "end tell" ; "tell application " & Quote ( "Microsoft Word" ) ; "create range active document start 0 end 23"; "set theRange to result"; "end tell" )
Agnes Riley Posted June 13, 2013 Author Posted June 13, 2013 Bruce, thanks for your replies. I do use a variable and have no problem opening Word. As I said the ONLY problem I have is with this line: "set theRange to (create range active document start 0 end 23)" The rest is working, thank you. Do you have an idea for that particular line? Thanks, Agi
bruceR Posted June 13, 2013 Posted June 13, 2013 I'm not sure if you revised your script along the lines I suggested. But I note that you're trying to do two things inside a system events - tell app process statement. The keystroke command will work. But the PROCESS does not understand the range command. The APPLICATION understands the range command. As written in my second example.
bruceR Posted June 14, 2013 Posted June 14, 2013 "The rest is working, thank you. Do you have an idea for that particular line?" ( the set range line) Yes. It is inside the wrong TELL statement. It only works when inside a tell application statement.
Agnes Riley Posted June 14, 2013 Author Posted June 14, 2013 Thanks, but I got it working. The problem was that the AppleScript couldn't be run from a variable, only from a field. I heard other people had this problem, as well. This is the working script calc in FM: "tell application " & Quote ( "Microsoft Word" ) & ¶ & "activate" & ¶ & "open" & Quote ( "Macintosh HD:Users:Shared:Guild_Word_Template.dotx") & ¶ & "set theDate to current date" & ¶ & "set text of active document to theDate as text" & ¶ & "save as active document file name " & Quote ( UIN_FOCUS::GT_WORD_FILE_NAME ) & ¶ & "end tell" & ¶ & "tell application " & Quote ( "System Events" ) & ¶ & "tell process " & Quote ( "Microsoft Word" ) & ¶ & "keystroke " & Quote ( "v" ) & " using {command down}" & ¶ & "end tell" & ¶ & "end tell" & ¶ & "tell application " & Quote("Microsoft Word") & ¶ & "set theRange to (create range active document start 0 end 23)" & ¶ & "select theRange" & ¶ & "tell paragraph format of theRange to set alignment to align paragraph center" & ¶ & "end tell" Of course, now I'm making my life more complicated by adding page breaks. But I'm getting there. :-) Now, my question is why I am not getting a notification from this forum, even though I'm following the toping with instant notification...
bruceR Posted June 15, 2013 Posted June 15, 2013 No that is not the prob. It DOES run from a variable.
Agnes Riley Posted June 15, 2013 Author Posted June 15, 2013 No, it does not from the variable. Others confirmed it, too.
bruceR Posted June 16, 2013 Posted June 16, 2013 Yes a perform AppleScript step does work from a variable. I use the method regularly and that was what i tested when diagnosing your missing tell application statement. I would have to see an example file showing how the attempts differ.
Recommended Posts
This topic is 4423 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now