18 Replies Latest reply on Jan 7, 2009 2:10 PM by (mps)

    Change tools?

    Level 1
      This is a bit odd, but I have a specialized project for which I've written a script that gets run with the cursor planted in text.

      When the script is done I'm selecting a frame the operator needs to be able to move around. However, selecting the frame doesn't change the cursor back to the selection tool, which is what the operator needs.

      Is there a way in the script to simply change to tools?

      Thanks,
      Ken
        • 1. Re: Change tools?
          Hi; same problem here. In one of my AppleScripts for InDesign 5.0.4 I simply want to toggle from the 'Selection Tool' to the 'Direct Selection Tool' and vice versa. In QuarkXPress 7 it's no problem:

          tell application "QuarkXPress Passport"
          activate
          tell document 1
          if tool mode is not equal to contents mode then
          set tool mode to contents mode
          else if tool mode is not equal to drag mode then
          set tool mode to drag mode
          end if
          end tell
          end tell

          So how can we do that in Indy?
          • 2. Re: Change tools?
            sstanleyau Level 4
            Can I ask why you want to do that?<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
            • 3. Re: Change tools?
              Level 1
              Yes. There are several reasons for this. For example:

              1.) Because it is for a script sequence that stops to let the user do creative/artistic things that cannot be scripted; and since it shall be a very user friendly script, it shall ensure that the appropriate tool is selected for the user to do his things. Otherwise the user would always have to select that tool manually with redundant mouse moves.

              2.) Because in Quark it's no problem at all.
              __
              German MacOSX.4.11 | English CS3 (Ps10.0.1, Ai13.0.2, Id5.0.4, Ac8.1.2), Quark 7.3.1
              • 4. Re: Change tools?
                sstanleyau Level 4
                Your first reason is a good one, but I can't see any solution short of<br />keyboard-emulating hacks.<br /><br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
                • 5. Re: Change tools?
                  Martin Fischer Level 2
                  Florian Bucher told in a german speaking forum how to do this:


                  app.menuActions.itemByName("Direct Selection Tool").invoke();


                  Martin Fischer
                  • 6. Re: Change tools?
                    sstanleyau Level 4
                    Cool. I could have sworn I came up empty when I went looking for that<br />command.<br /><br />-- <br />Shane Stanley <sstanley@myriad-com.com.au><br />AppleScript Pro Florida, April 2009 <a href=http://scriptingmatters.com/aspro>
                    • 7. Re: Change tools?
                      Martin Fischer Level 2
                      Hi Shane,

                      > I could have sworn I came up empty when I went looking for that
                      command.

                      So did I. ;-)

                      Martin Fischer
                      • 8. Re: Change tools?
                        Roy McCoy Level 1
                        So how would you do that with AppleScript?
                        Not that I would ever want to, of course. :-)
                        • 9. Re: Change tools?
                          Level 1
                          Woo-hoo! Made my morning! I've since had another application for this but had given up hope since my initial post was back in Oct.

                          I too had no luck finding information on this. If anyone has a source in which this type of thing can be searched electronically or, dare I say, I'd actually consider a good 'ol paper book, I'm ALL EARS.

                          Thanks yet again to all involved.

                          Ken
                          • 10. Re: Change tools?
                            Roy McCoy Level 1
                            Ken Krugh wrote:

                            Woo-hoo! Made my morning! [...]
                            I'd actually consider a good 'ol paper book, I'm ALL EARS.

                            My AppleScripting Indesign arrived today, so I'm in a good mood too. I don't see tools mentioned in either the index or the table of contents, so it would seem Shirley Hopkins, the author, wasn't aware of this capability either. Ole Kvern is the first person she credits for help with the book, big surprise there. I'll probably be registering my opinion on the book soon, though this won't be of much interest to the JavaScript and VBScript people. Amazon still has a copy or two, in any event. It's current to CS3, but she's considering a nominally priced update CD with info and new sample scripts for CS4.

                            Roy

                            • 11. Re: Change tools?
                              Level 1
                              Shane wrote: "I could have sworn I came up empty when I went looking for that command."

                              I was just about to look! Good find!

                              Actually, this is where the script that writes out the menu actions can come in handy. There are lots of menu actions that don't appear in the list of keyboard shortcuts (though this one should, as it's assignable).

                              Thanks,

                              Ole
                              • 12. Re: Change tools?
                                Level 1
                                Running this produces a long, long list of interesting stuff.
                                var myMenuActions = app.menuActions;
                                
                                var myArray = new Array;
                                for (var j = 0; myMenuActions.length > j; j++) {
                                  myArray.push(myMenuActions[j].name);
                                }
                                $.writeln(myArray.sort().join("\n"));
                                In my case, I have far too many scripts in my Scripting panel, that's for sure. Thanks to aliases of folder, about every script I ever wrote is visible as a menuAction.

                                Dave
                                • 13. Re: Change tools?
                                  Level 1
                                  Hi Dave,

                                  That's exactly what GetMenuActions.jsx (part of the Scripting Guide set) does, except it writes a text file to disk.

                                  Thanks,

                                  Ole
                                  • 14. Re: Change tools?
                                    Roy McCoy Level 1
                                    This thing with changing tools turning out to be scriptable makes me
                                    wonder about two general questions, both of which have presumably been
                                    formulated and answered before but I'll ask them again anyway.

                                    1. I've seen somewhere that "just about anything" that could be done
                                    via the menus or GUI in InDesign could be scripted, or words to that
                                    effect. What are the exceptions, if any? In other words, what can't be
                                    scripted in InDesign?

                                    2. Inversely, what can be scripted that can't be done via the menus or
                                    GUI? If there are many things, is there a way in which these may be
                                    generally characterized?


                                    Thanks,

                                    Roy McCoy
                                    Rotterdam, NL
                                    • 15. Re: Change tools?
                                      Level 1
                                      You can't via a script set a document to have script attachability -- if you could, it would rather defeat the purpose of the preference.

                                      You can via a script "paste into" an object multiple other objects. See:

                                      http://indesignsecrets.com/easily-add-captions-to-graphics-frames.php

                                      for an example of this.

                                      I think there are a couple more preferences that aren't accessible.

                                      I don't think I can provide a general characterization.

                                      Dave
                                      • 16. Re: Change tools?
                                        Roy McCoy Level 1
                                        I think you have, though, suggesting that there really isn't very much
                                        you can't script.


                                        Thanks,

                                        Roy
                                        • 17. Re: Change tools?
                                          Level 1
                                          Well that's certainly true. Bear in mind also that there are things that are technically possible in the UI that would be unbearably tedious but which a script can just gobble up with the infinite patience of the automoton. On the other hand, there are aesthetic judgments that can be made in working with the UI that are the devil's own job to automate.

                                          Dave
                                          • 18. Re: Change tools?
                                            Very new to scripting, when I run this I get errors.

                                            app.menuActions.itemByName("Direct Selection Tool").invoke();

                                            Trying to invoke File>Open. I ran the list of menuActions script and I have a list now, but it does me no good if my understanding of the implementation isn't there.

                                            I appreciate any help, thanks!