Loading ...
Sorry, an error occurred while loading the content.

Re: [wpmac] Document with macros causes AppleScript timeout?

Expand Messages
  • em315
    John, ... set myFile to Converter:Desktop Folder:infile as alias tell application Corel WordPerfect launch end tell pause for 2 with seconds timing --Akua
    Message 1 of 11 , Jan 11, 2011
    • 0 Attachment
      John,

      The problem is more complicated than a timing problem. Running under System 7.5.5, I tried using this AppleScript to open the About 3.5 Enhanced file (copied to "infile"):

      --------------

      set myFile to "Converter:Desktop Folder:infile" as alias
      tell application "Corel WordPerfect"
      launch
      end tell
      pause for 2 with seconds timing --Akua Scripts pause equivalent
      tell application "Corel WordPerfect"
      open myFile
      end tell
      error number -128

      ---------------

      WP immediately presents the "Macro Terminated" message - apparently simply because it was opened from an AppleScript.

      What is happening here??


      --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
      >
      >
      >
      > Hi Bob,
      >
      > Nice to see you again. Your Applescript advice is very helpful stuff, but I wonder whether that's the problem here. The About WP 3.5 Enhanced has an OnOpenDocument macro, which is just
      >
      > Display (Off)
      > End ()
      > Home ()
      > Display (On)
      >
      > which reads the document into RAM so that subsequent navigation will be faster. The doc is 68 pages but, with display off, would only take a second to execute. That could still be the problem -- that the Applescript save command won't execute while the macro is running. A timeout could help, or a Delay (seconds)
      > command, e.g. Delay 2, inbetween the commands to WP, might work.
      >
    • em315
      Of course I meant Akua Sweets not Akua Scripts ...
      Message 2 of 11 , Jan 12, 2011
      • 0 Attachment
        Of course I meant "Akua Sweets" not "Akua Scripts"...

        --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:
        >
        > John,
        >
        > The problem is more complicated than a timing problem. Running under System 7.5.5, I tried using this AppleScript to open the About 3.5 Enhanced file (copied to "infile"):
        >
        > --------------
        >
        > set myFile to "Converter:Desktop Folder:infile" as alias
        > tell application "Corel WordPerfect"
        > launch
        > end tell
        > pause for 2 with seconds timing --Akua Scripts pause equivalent
        > tell application "Corel WordPerfect"
        > open myFile
        > end tell
        > error number -128
        >
        > ---------------
        >
        > WP immediately presents the "Macro Terminated" message - apparently simply because it was opened from an AppleScript.
        >
        > What is happening here??
        >
      • John R
        With my SheepShaver setup, running your script worked fine the first time. The second time (quitting WP between runs) I got the macro terminated error, and the
        Message 3 of 11 , Jan 12, 2011
        • 0 Attachment
          With my SheepShaver setup, running your script worked fine the first time. The second time (quitting WP between runs) I got the macro terminated error, and the status bar, which had been set to show, failed to show. When I went to Edit > Preferences to look at this, WP hung. I force-quit and replaced Prefs with a backup copy.

          Applescript's Launch command runs an application but without running its startup scripts, if any, whether identified to the user as macros or otherwise. With WP not running, telling it to launch and open a file that contains an OnOpenDocument macro, i.e. a startup script, might produce an unexpected interaction between the system and WP.

          The Launch command is typically not widely used. The Run command is used more: this launches the app and runs its startup script. Even more common is the Activate command, which launches the app, runs its startup script, and brings it to the front. The advantages of activation are that whatever else you want WP to do will happen faster, it being the frontmost app; the clipboard is accessible, and possibly other things.

          Modifying the script to:

          set myFile to "SheepShaver:About WordPerfect 3.5 Enhanced" as alias
          tell application WordPerfect to open myFile

          works successive times without problems. This runs WP and opens the file, but without bringing it to the front. To do that, you could do:

          set myFile to "SheepShaver:About WordPerfect 3.5 Enhanced" as alias
          tell application "WordPerfect"
          activate
          open myFile
          end tell

          although if WP is not already running, activate or just open (which implies run) will open a new blank document as well.

          But I like to use the Finder to open a file. Straightforward and can work better than WP's first-generation support for AS. It will open a file using the file's creator unless you specify another application.

          So what I'd do is:

          set myFile to "SheepShaver:About WordPerfect 3.5 Enhanced" as alias
          tell application "Finder" to open myFile

          which opens the file without a new blank file in case WP is not running, brings the opened file to the front, and appears to have no interaction with the OnOpenDocument macro.

          >Of course I meant "Akua Sweets" not "Akua Scripts"...s)

          "Sweets" in the title is a play on words with "suites" of Applescript commands and objects, of which this redoubtable osax has more than any other ever written.

          John R.



          --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:
          >
          > John,
          >
          > The problem is more complicated than a timing problem. Running under System 7.5.5, I tried using this AppleScript to open the About 3.5 Enhanced file (copied to "infile"):
          >
          > --------------
          >
          > set myFile to "Converter:Desktop Folder:infile" as alias
          > tell application "Corel WordPerfect"
          > launch
          > end tell
          > pause for 2 with seconds timing --Akua Scripts pause equivalent
          > tell application "Corel WordPerfect"
          > open myFile
          > end tell
          > error number -128
          >
          > ---------------
          >
          > WP immediately presents the "Macro Terminated" message - apparently simply because it was opened from an AppleScript.
          >
          > What is happening here??
        • em315
          John, Apologies for causing a crash that demolished your preference files - and a thousand thanks for your solution to this problem. As you know, all my
          Message 4 of 11 , Jan 12, 2011
          • 0 Attachment
            John,

            Apologies for causing a crash that demolished your preference files - and a thousand thanks for your solution to this problem. As you know, all my knowledge of AppleScript comes from messing up other people's scripts while trying to adapt them, and it simply never occurred to me to use the Finder to open the document instead of telling WordPerfect to open it. I tried to solve the problem by using multiple "tells" - one to WP to start, another to open the file, etc. - but that simply compounded the problem.

            Your solution makes the whole process run more reliably and more quickly. I think I've now completed this project, and will post a link to it tomorrow. Basically, what it is a droplet/ application that converts any WP file to RTF, DOC, or PDF - and that converts WPMac 3.5e files to WPDOS 5.1 or 6.x format so that the cross-references, etc., can be used in Windows applications. It uses WPMac 3.5e for some functions, and the WP DOS-based ConvertPerfect for others, and a few other programs for still other purposes. I don't know if anyone can use it, but it was an enjoyable challenge to put it together.

            Thanks again for this elegant and efficient solution.


            --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
            >
            > But I like to use the Finder to open a file. Straightforward and can work better than WP's first-generation support for AS. It will open a file using the file's creator unless you specify another application.
            >
            > So what I'd do is:
            >
            > set myFile to "SheepShaver:About WordPerfect 3.5 Enhanced" as alias
            > tell application "Finder" to open myFile
            >
            > which opens the file without a new blank file in case WP is not running, brings the opened file to the front, and appears to have no interaction with the OnOpenDocument macro.
          • John R
            No apology needed, certainly. The cause of the crash, I m guessing, was an interaction between Applescript s Launch command and an OnOpenDocument macro. In any
            Message 5 of 11 , Jan 14, 2011
            • 0 Attachment
              No apology needed, certainly. The cause of the crash, I'm guessing, was an interaction between Applescript's Launch command and an OnOpenDocument macro.

              In any case, I had a backup Prefs file all ready to go. This is why I recommend that every user, if you haven't already done so:

              1. Quit WP
              2. Go to System Folder > Preferences > WordPerfect and trash your Preferences (USA) -- or e.g. Preferences (CAN) -- file. Archive your Library file while you're at it.
              3. Start WP. It will take a little longer since it's building a new Prefs file.
              4. Set all your preferences to your liking.
              5. Quit WP again and archive your new Preferences file.

              When a copy of WP is acting up, the first step I recommend doing is quitting and replacing the current Prefs file with a copy of the archive.

              John R.



              --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:
              >
              > John,
              >
              > Apologies for causing a crash that demolished your preference files - and a thousand thanks for your solution to this problem. As you know, all my knowledge of AppleScript comes from messing up other people's scripts while trying to adapt them, and it simply never occurred to me to use the Finder to open the document instead of telling WordPerfect to open it. I tried to solve the problem by using multiple "tells" - one to WP to start, another to open the file, etc. - but that simply compounded the problem.
              >
              > Your solution makes the whole process run more reliably and more quickly. I think I've now completed this project, and will post a link to it tomorrow. Basically, what it is a droplet/ application that converts any WP file to RTF, DOC, or PDF - and that converts WPMac 3.5e files to WPDOS 5.1 or 6.x format so that the cross-references, etc., can be used in Windows applications. It uses WPMac 3.5e for some functions, and the WP DOS-based ConvertPerfect for others, and a few other programs for still other purposes. I don't know if anyone can use it, but it was an enjoyable challenge to put it together.
              >
              > Thanks again for this elegant and efficient solution.
              >
              >
              > --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@> wrote:
              > >
              > > But I like to use the Finder to open a file. Straightforward and can work better than WP's first-generation support for AS. It will open a file using the file's creator unless you specify another application.
              > >
              > > So what I'd do is:
              > >
              > > set myFile to "SheepShaver:About WordPerfect 3.5 Enhanced" as alias
              > > tell application "Finder" to open myFile
              > >
              > > which opens the file without a new blank file in case WP is not running, brings the opened file to the front, and appears to have no interaction with the OnOpenDocument macro.
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.