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

Re: Macro question: place variable in Mac OS clipboard?

Expand Messages
  • em315
    ... try tell application WordPerfect to set frontWindow to name of window 1 on error errmsg tell me to activate display dialog errmsg error number -128 end
    Message 1 of 14 , Mar 20, 2013
    • 0 Attachment
      Here's something strange. The following script works when run from the Script Editor:

      -----
      try
      tell application "WordPerfect" to set frontWindow to name of window 1
      on error errmsg
      tell me to activate
      display dialog errmsg
      error number -128
      end try
      tell me to activate
      display dialog frontWindow
      -----

      But if I use an "Execute Apple Script" command in a WP macro to run the script, then nothing happens. It seems to exit silently.

      However, the following variation does seem to work when I use an "Execute Apple Script" command in a macro to launch it:

      -----
      try
      tell application "WordPerfect" to set frontWindow to name of window 1
      on error errmsg
      tell me to activate
      display dialog errmsg
      error number -128
      end try
      set the clipboard to frontWindow
      set pdfName to string of (the clipboard as record)
      tell me to activate
      display dialog pdfName
      ------

      What on earth is going on here??

      --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
      >
      > Would an Applescript work there?
      >
      > tell application "WordPerfect" to set frontWindow to name of window 1
      > set the clipboard to frontWindow
      >
      > John R.
      >
      >
      > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
      > >
      > > Is there an easy way to put a WP variable into the Mac OS clipboard without opening a new window in WP?
      > >
      > > I'm trying to put the title of the front window into the Mac OS clipboard without opening a new window, writing it into it, selecting it, and copying it to the clipboard.
      > >
      > > The only thing I can think of is to write the FrontWindow variable into the current file (maybe in a text box), select it and cut it (and then cut the text box it's in), but this seems extremely unreliable and awkward.
      > >
      > > There must be a better way, and I'll be glad to know about any possibilities.
      > >
      >
    • em315
      Now that you ve answered one question, may I bother you with another: Can I use an AppleScript to get the value of a Global Variable in WordPerfect? In other
      Message 2 of 14 , Mar 20, 2013
      • 0 Attachment
        Now that you've answered one question, may I bother you with another:

        Can I use an AppleScript to get the value of a Global Variable in WordPerfect?

        In other words, is it possible to have an AppleScript that says something like this:

        tell application "WordPerfect"
        set myVar to GlobalVar26
        end tell
        tell me to activate
        display dialog myVar


        --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
        >
        > Would an Applescript work there?
        >
        > tell application "WordPerfect" to set frontWindow to name of window 1
        > set the clipboard to frontWindow
        >
        > John R.
        >
        >
        > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
        > >
        > > Is there an easy way to put a WP variable into the Mac OS clipboard without opening a new window in WP?
        > >
        > > I'm trying to put the title of the front window into the Mac OS clipboard without opening a new window, writing it into it, selecting it, and copying it to the clipboard.
        > >
        > > The only thing I can think of is to write the FrontWindow variable into the current file (maybe in a text box), select it and cut it (and then cut the text box it's in), but this seems extremely unreliable and awkward.
        > >
        > > There must be a better way, and I'll be glad to know about any possibilities.
        > >
        >
      • John R
        No idea as to specifics, except that the clipboard can be complicated. It exists as a record, so coercions such as (clipboard as string) are often useful. I
        Message 3 of 14 , Mar 21, 2013
        • 0 Attachment
          No idea as to specifics, except that the clipboard can be complicated. It exists as a record, so coercions such as (clipboard as string) are often useful.

          I also don't know whether WP's absolutely first-generation support for Applescript could play a role. I know that property values don't update in a script written to update them, when the script is run with Execute Apple Script.

          For a few reasons, while I see the combination of Applescript and WP macros as a very powerful scripting environment, I like to code the 'big picture' in Applescript, getting only a little bit from WP, e.g. text of document 1, and then work using a largely Applescript structure that sends Do Script commands to WP (you can also send 50 variables to WP, while if a WP macro calls an Applescript there's no way except the clipboard to pass data).

          John R.


          --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:

          > What on earth is going on here??
        • John R
          I don t know of a way to do that. But again (see last post), I d try to generate a value in Applescript and pass that to WP instead of the other way around.
          Message 4 of 14 , Mar 21, 2013
          • 0 Attachment
            I don't know of a way to do that. But again (see last post), I'd try to generate a value in Applescript and pass that to WP instead of the other way around.

            John R.



            --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:
            >
            > Now that you've answered one question, may I bother you with another:
            >
            > Can I use an AppleScript to get the value of a Global Variable in WordPerfect?
            >
            > In other words, is it possible to have an AppleScript that says something like this:
            >
            > tell application "WordPerfect"
            > set myVar to GlobalVar26
            > end tell
            > tell me to activate
            > display dialog myVar
            >
          • em315
            That s exactly what I did in the version that I posted yesterday. I used an Applescript to prompt the user for a default zoom level; then I save it to the
            Message 5 of 14 , Mar 21, 2013
            • 0 Attachment
              That's exactly what I did in the version that I posted yesterday. I used an Applescript to prompt the user for a default zoom level; then I save it to the clipboard so that WP can copy it from the clipboard to a global variable, which is used by the OnOpenDocument macro (and a New Document Template is in the Templates folder so that new documents get the same zoom level).

              The same Applescript saves a text file that contains the zoom-level number.

              An OnStartup macro that runs when WP starts up runs an Applescript that reads the text file for the zoom-level number and copies it to the clipboard - so that the WP macro can copy the number from the clipboard to a global variable. It seems to work.

              Again, this is entirely your idea - I just banged my forehead on the trackpad until the code seemed to work.


              --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
              >
              > I don't know of a way to do that. But again (see last post), I'd try to generate a value in Applescript and pass that to WP instead of the other way around.
              >
              > John R.
              >
              >
              >
              > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
              > >
              > > Now that you've answered one question, may I bother you with another:
              > >
              > > Can I use an AppleScript to get the value of a Global Variable in WordPerfect?
              > >
              > > In other words, is it possible to have an AppleScript that says something like this:
              > >
              > > tell application "WordPerfect"
              > > set myVar to GlobalVar26
              > > end tell
              > > tell me to activate
              > > display dialog myVar
              > >
              >
            • John R
              Looks like it would work fine. I d probably steer clear of the clipboard and pass the value to WP with a neutral (and in this case often helpful) macro like
              Message 6 of 14 , Mar 23, 2013
              • 0 Attachment
                Looks like it would work fine. I'd probably steer clear of the clipboard and pass the value to WP with a neutral (and in this case often helpful) macro like Redraw, adding a parameter to it that WP accepts as a script variable. Script variables 1-50 are global in scope.

                set theZoom to text returned of (display dialog "Enter zoom level:") etc.
                tell app "WordPerfect" to do script {"Redraw",theZoom)

                placing the numeric string into ScriptVar01.

                John R.


                --- In wordperfectmac@yahoogroups.com, "em315" <em315@...> wrote:
                >
                > That's exactly what I did in the version that I posted yesterday. I used an Applescript to prompt the user for a default zoom level; then I save it to the clipboard so that WP can copy it from the clipboard to a global variable, which is used by the OnOpenDocument macro (and a New Document Template is in the Templates folder so that new documents get the same zoom level).
                >
                > The same Applescript saves a text file that contains the zoom-level number.
                >
                > An OnStartup macro that runs when WP starts up runs an Applescript that reads the text file for the zoom-level number and copies it to the clipboard - so that the WP macro can copy the number from the clipboard to a global variable. It seems to work.
                >
                > Again, this is entirely your idea - I just banged my forehead on the trackpad until the code seemed to work.
                >
                >
                > --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@> wrote:
                > >
                > > I don't know of a way to do that. But again (see last post), I'd try to generate a value in Applescript and pass that to WP instead of the other way around.
                > >
                > > John R.
                > >
                > >
                > >
                > > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
                > > >
                > > > Now that you've answered one question, may I bother you with another:
                > > >
                > > > Can I use an AppleScript to get the value of a Global Variable in WordPerfect?
                > > >
                > > > In other words, is it possible to have an AppleScript that says something like this:
                > > >
                > > > tell application "WordPerfect"
                > > > set myVar to GlobalVar26
                > > > end tell
                > > > tell me to activate
                > > > display dialog myVar
                > > >
                > >
                >
              • John R
                s/b set theZoom to text returned of (display dialog Enter zoom level: ) etc. tell app WordPerfect to do script { Redraw ,theZoom} with curly brackets around
                Message 7 of 14 , Mar 23, 2013
                • 0 Attachment
                  s/b

                  set theZoom to text returned of (display dialog "Enter zoom level:") etc.
                  tell app "WordPerfect" to do script {"Redraw",theZoom}

                  with curly brackets around script name and parameters.




                  --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
                  >
                  > Looks like it would work fine. I'd probably steer clear of the clipboard and pass the value to WP with a neutral (and in this case often helpful) macro like Redraw, adding a parameter to it that WP accepts as a script variable. Script variables 1-50 are global in scope.
                  >
                  > set theZoom to text returned of (display dialog "Enter zoom level:") etc.
                  > tell app "WordPerfect" to do script {"Redraw",theZoom)
                  >
                  > placing the numeric string into ScriptVar01.
                  >
                  > John R.
                  >
                  >
                  > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
                  > >
                  > > That's exactly what I did in the version that I posted yesterday. I used an Applescript to prompt the user for a default zoom level; then I save it to the clipboard so that WP can copy it from the clipboard to a global variable, which is used by the OnOpenDocument macro (and a New Document Template is in the Templates folder so that new documents get the same zoom level).
                  > >
                  > > The same Applescript saves a text file that contains the zoom-level number.
                  > >
                  > > An OnStartup macro that runs when WP starts up runs an Applescript that reads the text file for the zoom-level number and copies it to the clipboard - so that the WP macro can copy the number from the clipboard to a global variable. It seems to work.
                  > >
                  > > Again, this is entirely your idea - I just banged my forehead on the trackpad until the code seemed to work.
                  > >
                  > >
                  > > --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@> wrote:
                  > > >
                  > > > I don't know of a way to do that. But again (see last post), I'd try to generate a value in Applescript and pass that to WP instead of the other way around.
                  > > >
                  > > > John R.
                  > > >
                  > > >
                  > > >
                  > > > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
                  > > > >
                  > > > > Now that you've answered one question, may I bother you with another:
                  > > > >
                  > > > > Can I use an AppleScript to get the value of a Global Variable in WordPerfect?
                  > > > >
                  > > > > In other words, is it possible to have an AppleScript that says something like this:
                  > > > >
                  > > > > tell application "WordPerfect"
                  > > > > set myVar to GlobalVar26
                  > > > > end tell
                  > > > > tell me to activate
                  > > > > display dialog myVar
                  > > > >
                  > > >
                  > >
                  >
                • em315
                  Thank you - a much better solution than mine. Will implement later...
                  Message 8 of 14 , Mar 23, 2013
                  • 0 Attachment
                    Thank you - a much better solution than mine. Will implement later...

                    --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
                    >
                    > s/b
                    >
                    > set theZoom to text returned of (display dialog "Enter zoom level:") etc.
                    > tell app "WordPerfect" to do script {"Redraw",theZoom}
                    >
                    > with curly brackets around script name and parameters.
                    >
                    >
                    >
                    >
                    > --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@> wrote:
                    > >
                    > > Looks like it would work fine. I'd probably steer clear of the clipboard and pass the value to WP with a neutral (and in this case often helpful) macro like Redraw, adding a parameter to it that WP accepts as a script variable. Script variables 1-50 are global in scope.
                    > >
                    > > set theZoom to text returned of (display dialog "Enter zoom level:") etc.
                    > > tell app "WordPerfect" to do script {"Redraw",theZoom)
                    > >
                    > > placing the numeric string into ScriptVar01.
                    > >
                    > > John R.
                    > >
                    > >
                    > > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
                    > > >
                    > > > That's exactly what I did in the version that I posted yesterday. I used an Applescript to prompt the user for a default zoom level; then I save it to the clipboard so that WP can copy it from the clipboard to a global variable, which is used by the OnOpenDocument macro (and a New Document Template is in the Templates folder so that new documents get the same zoom level).
                    > > >
                    > > > The same Applescript saves a text file that contains the zoom-level number.
                    > > >
                    > > > An OnStartup macro that runs when WP starts up runs an Applescript that reads the text file for the zoom-level number and copies it to the clipboard - so that the WP macro can copy the number from the clipboard to a global variable. It seems to work.
                    > > >
                    > > > Again, this is entirely your idea - I just banged my forehead on the trackpad until the code seemed to work.
                    > > >
                    > > >
                    > > > --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@> wrote:
                    > > > >
                    > > > > I don't know of a way to do that. But again (see last post), I'd try to generate a value in Applescript and pass that to WP instead of the other way around.
                    > > > >
                    > > > > John R.
                    > > > >
                    > > > >
                    > > > >
                    > > > > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
                    > > > > >
                    > > > > > Now that you've answered one question, may I bother you with another:
                    > > > > >
                    > > > > > Can I use an AppleScript to get the value of a Global Variable in WordPerfect?
                    > > > > >
                    > > > > > In other words, is it possible to have an AppleScript that says something like this:
                    > > > > >
                    > > > > > tell application "WordPerfect"
                    > > > > > set myVar to GlobalVar26
                    > > > > > end tell
                    > > > > > tell me to activate
                    > > > > > display dialog myVar
                    > > > > >
                    > > > >
                    > > >
                    > >
                    >
                  • em315
                    Thanks for this suggestion. I ve now implemented your suggestion, and left the clipboard untouched, which I wanted to do all along. New version posted now. So
                    Message 9 of 14 , Mar 23, 2013
                    • 0 Attachment
                      Thanks for this suggestion. I've now implemented your suggestion, and left the clipboard untouched, which I wanted to do all along. New version posted now.

                      So basically this code is entirely yours. Thanks again.

                      --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@...> wrote:
                      >
                      > Looks like it would work fine. I'd probably steer clear of the clipboard and pass the value to WP with a neutral (and in this case often helpful) macro like Redraw, adding a parameter to it that WP accepts as a script variable. Script variables 1-50 are global in scope.
                      >
                      > set theZoom to text returned of (display dialog "Enter zoom level:") etc.
                      > tell app "WordPerfect" to do script {"Redraw",theZoom)
                      >
                      > placing the numeric string into ScriptVar01.
                      >
                      > John R.
                      >
                      >
                      > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
                      > >
                      > > That's exactly what I did in the version that I posted yesterday. I used an Applescript to prompt the user for a default zoom level; then I save it to the clipboard so that WP can copy it from the clipboard to a global variable, which is used by the OnOpenDocument macro (and a New Document Template is in the Templates folder so that new documents get the same zoom level).
                      > >
                      > > The same Applescript saves a text file that contains the zoom-level number.
                      > >
                      > > An OnStartup macro that runs when WP starts up runs an Applescript that reads the text file for the zoom-level number and copies it to the clipboard - so that the WP macro can copy the number from the clipboard to a global variable. It seems to work.
                      > >
                      > > Again, this is entirely your idea - I just banged my forehead on the trackpad until the code seemed to work.
                      > >
                      > >
                      > > --- In wordperfectmac@yahoogroups.com, "John R" <johnrethorst@> wrote:
                      > > >
                      > > > I don't know of a way to do that. But again (see last post), I'd try to generate a value in Applescript and pass that to WP instead of the other way around.
                      > > >
                      > > > John R.
                      > > >
                      > > >
                      > > >
                      > > > --- In wordperfectmac@yahoogroups.com, "em315" <em315@> wrote:
                      > > > >
                      > > > > Now that you've answered one question, may I bother you with another:
                      > > > >
                      > > > > Can I use an AppleScript to get the value of a Global Variable in WordPerfect?
                      > > > >
                      > > > > In other words, is it possible to have an AppleScript that says something like this:
                      > > > >
                      > > > > tell application "WordPerfect"
                      > > > > set myVar to GlobalVar26
                      > > > > end tell
                      > > > > tell me to activate
                      > > > > display dialog myVar
                      > > > >
                      > > >
                      > >
                      >
                    Your message has been successfully submitted and would be delivered to recipients shortly.