June 12, 201312 yr 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
June 12, 201312 yr 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 ]
June 12, 201312 yr 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" )
June 13, 201312 yr Author 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
June 13, 201312 yr 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.
June 14, 201312 yr "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.
June 14, 201312 yr Author 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...
June 16, 201312 yr 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.
Create an account or sign in to comment