Jump to content
Server Maintenance This Week. ×

This topic is 3965 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

Link to comment
Share on other sites

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 ]

Link to comment
Share on other sites

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"
)
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

"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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This topic is 3965 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.