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

Re: [Was: WPMac stalls during startup] Problem with background script

Expand Messages
  • John R
    ... The more I look at this, the less I can figure out. Running my earlier test script a few times, I saw that an error number -128 in an idle handler will
    Message 1 of 15 , Jan 18, 2012
    • 0 Attachment
      --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:

      > the mystery is why sometimes - but only sometimes - when I tell the Mac OS to quit (and thus quit SheepShaver), and my background script is running in the background, WP starts up and blocks the shutdown.

      The more I look at this, the less I can figure out. Running my earlier test script a few times, I saw that an error number -128 in an idle handler will sometimes not exit the handler. But you're not doing that here; all I can think of is that even if there isn't a transferDoc file in the expected folder, the handler continues to execute and WP launches. I'd think it's not necessary to launch WP; if the script tells the program to open a file, that would run the program. I'm sorry that I can't see anything more useful at this point.

      FWIW here's a few much less important questions and suggestions, prefaced by a "--**" on each line.


      on idle
      if alreadyOpen is 1 then
      tell application "Finder"
      if exists (some process whose name contains "Corel WordPerfect") then
      tell application "WordPerfect" to activate
      set alreadyOpen to 0
      end if
      end tell
      end if

      --** instead of <if exists some process whose name contains> (or process 1 whose name contains), why not
      --** do <if creator type of processes contains "WPC2">, since the user may have changed the name of the app,

      try
      tell application "Finder" to set transferDoc to transferFile as alias
      on error
      return 0.5
      end try

      set tid to text item delimiters
      set text item delimiters to return

      set filePaths to (read transferDoc)
      set fileList to text items of filePaths

      tell application "WordPerfect"
      launch
      --Do Script "On Startup"

      --** the automatic script needs to be named <OnStartup> without a space to work as such in WP..
      --** The launch command starts WP without running the script. Nothing wrong with either way,
      --** but what's the advantage of not running the script?

      if fileList is "" then
      else

      --** you could do <if fileList is not "" then> but there should be content in fileList at this point,
      --** unless transferDoc for some reason has no text in it that could be file paths.
      --** Probably best to have this check though.

      repeat with i from 1 to ((count items in fileList) - 1)
      try
      set thisFile to (item i of fileList as string)
      open (thisFile as alias)
      on error
      display dialog "I could not open "" & thisFile & ""." buttons ¬
      {"OK"} default button 1 with icon caution
      exit repeat
      end try
      end repeat
      end if
      end tell

      try
      deleteFile transferDoc -- Jon's Commands
      on error
      tell application "Finder" to delete transferDoc
      end try

      set text item delimiters to tid
      set fileList to ""
      return 0.5
      end idle
    • em315
      Many thanks for this. Adding the On Startup script was my mistake - I didn t know there was an OnStartup macro that launched automatically on startup. So
      Message 2 of 15 , Jan 19, 2012
      • 0 Attachment
        Many thanks for this. Adding the "On Startup" script was my mistake - I didn't know there was an "OnStartup" macro that launched automatically on startup. So may I assume I'm right in thinking that there's no need to specify that OnStartup should run, because it runs anyway?

        I've made that change, and have also changed the part that tests for the process - I now use your method of checking for the process that contains WPC2.

        I didn't (yet) change from launching WP and opening the file to simply opening the file (presumably by telling application "Finder" to open it), but will do so later. Meanwhile, I've prepared the slightly revised version for uploading and will do so today.

        Will experiment with the change from launch-WP-and-open to just open later and will add then when I'm sure it works.

        Thank you again for this. I don't actually use this - I use WPDOS - but I enjoy putting this together as a mental exercise and public service.



        --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
        >
        > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
        >
        > > the mystery is why sometimes - but only sometimes - when I tell the Mac OS to quit (and thus quit SheepShaver), and my background script is running in the background, WP starts up and blocks the shutdown.
        >
        > The more I look at this, the less I can figure out. Running my earlier test script a few times, I saw that an error number -128 in an idle handler will sometimes not exit the handler. But you're not doing that here; all I can think of is that even if there isn't a transferDoc file in the expected folder, the handler continues to execute and WP launches. I'd think it's not necessary to launch WP; if the script tells the program to open a file, that would run the program. I'm sorry that I can't see anything more useful at this point.
        >
        > FWIW here's a few much less important questions and suggestions, prefaced by a "--**" on each line.
        >
        >
        > on idle
        > if alreadyOpen is 1 then
        > tell application "Finder"
        > if exists (some process whose name contains "Corel WordPerfect") then
        > tell application "WordPerfect" to activate
        > set alreadyOpen to 0
        > end if
        > end tell
        > end if
        >
        > --** instead of <if exists some process whose name contains> (or process 1 whose name contains), why not
        > --** do <if creator type of processes contains "WPC2">, since the user may have changed the name of the app,
        >
        > try
        > tell application "Finder" to set transferDoc to transferFile as alias
        > on error
        > return 0.5
        > end try
        >
        > set tid to text item delimiters
        > set text item delimiters to return
        >
        > set filePaths to (read transferDoc)
        > set fileList to text items of filePaths
        >
        > tell application "WordPerfect"
        > launch
        > --Do Script "On Startup"
        >
        > --** the automatic script needs to be named <OnStartup> without a space to work as such in WP..
        > --** The launch command starts WP without running the script. Nothing wrong with either way,
        > --** but what's the advantage of not running the script?
        >
        > if fileList is "" then
        > else
        >
        > --** you could do <if fileList is not "" then> but there should be content in fileList at this point,
        > --** unless transferDoc for some reason has no text in it that could be file paths.
        > --** Probably best to have this check though.
        >
        > repeat with i from 1 to ((count items in fileList) - 1)
        > try
        > set thisFile to (item i of fileList as string)
        > open (thisFile as alias)
        > on error
        > display dialog "I could not open "" & thisFile & ""." buttons ¬
        > {"OK"} default button 1 with icon caution
        > exit repeat
        > end try
        > end repeat
        > end if
        > end tell
        >
        > try
        > deleteFile transferDoc -- Jon's Commands
        > on error
        > tell application "Finder" to delete transferDoc
        > end try
        >
        > set text item delimiters to tid
        > set fileList to ""
        > return 0.5
        > end idle
        >
      • John R
        ... if WP is not running: tell application WordPerfect to activate -- runs OnStartup, opens new document, brings app to front tell application WordPerfect
        Message 3 of 15 , Jan 23, 2012
        • 0 Attachment
          --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:

          > So may I assume I'm right in thinking that there's no need to specify that OnStartup should run, because it runs anyway?

          if WP is not running:

          tell application "WordPerfect" to activate
          --> runs OnStartup, opens new document, brings app to front

          tell application "WordPerfect" to run
          --> runs OnStartup, opens new document, does not bring app to front

          tell application "WordPerfect" to launch
          --> loads app into memory but doesn't do anything else

          If WP is running, the launch and run commands do nothing; the activate command brings the app to the front.

          > Thank you again for this. I don't actually use this - I use WPDOS - but I enjoy putting this together as a mental exercise and public service.

          It's a great public service. Thank you.

          John R.
        • em315
          Thank you for this - it lets me sort out my script a bit more. I ll upload an improved version by the morning. The new version adds one more feature. It
          Message 4 of 15 , Jan 23, 2012
          • 0 Attachment
            Thank you for this - it lets me sort out my script a bit more. I'll upload an improved version by the morning.

            The new version adds one more feature. It occurred to me that it might be useful to shutdown SheepShaver in an orderly way by running a script in OS X that would tell SheepShaver to shut down.

            So I've written a script that will do exactly that with the WPMacApp, provided that the user hasn't quit the script that runs in the background in SheepShaver when it's running. A copy of the script is stored inside the WPMacApp. (Show Package Contents ->Resources->Files and copy the ShutdownWPMacApp application somewhere else.) When you run the ShutdownWPMacApp application in OS X, a few seconds later, the WPMacApp itself will shut down. All this, of course, is based on your method of using AppleScript to communicate between OS X and SheepShaver.

            --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
            >
            > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
            >
            > > So may I assume I'm right in thinking that there's no need to specify that OnStartup should run, because it runs anyway?
            >
            > if WP is not running:
            >
            > tell application "WordPerfect" to activate
            > --> runs OnStartup, opens new document, brings app to front
            >
            > tell application "WordPerfect" to run
            > --> runs OnStartup, opens new document, does not bring app to front
            >
            > tell application "WordPerfect" to launch
            > --> loads app into memory but doesn't do anything else
            >
            > If WP is running, the launch and run commands do nothing; the activate command brings the app to the front.
            >
            > > Thank you again for this. I don't actually use this - I use WPDOS - but I enjoy putting this together as a mental exercise and public service.
            >
            > It's a great public service. Thank you.
            >
            > John R.
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.