Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

commandFromAction() script help

TXS - Help
2014-07-30
2014-09-09
  • CLightfield
    CLightfield
    2014-07-30

    I'm trying to write a "magic comment" script that will open the PDF in viewer upon opening the .tex file. The slot for view-pdf is commandFromAction(), but I'm not sure how to call that specific command. What I tried is the following:

    % !TeX TXS-SCRIPT = foobar
    % //Trigger = ?load-this-file
    % app.commandFromAction(view-pdf);
    % TXS-SCRIPT-END

    but this doesn't work. It's reading "view" as a variable and throwing an error. I would appreciate any help on getting this script to work.

    Thanks,
    CL

     
    • Tim Hoffmann
      Tim Hoffmann
      2014-07-30

      The slot for view-pdf is commandFromAction(),

      Right. The slot is already connected, i.e. all the logic is in place.
      You just need the action associated with "View" and trigger it
      (equivalent to clicking on the menu entry of the action). Do this.

      app.getManagedAction("main/tools/view").trigger()

       
      Attachments
      • CLightfield
        CLightfield
        2014-07-30

        Thanks Tim! I have a user command (called “Alternate”) that works for me when ran by clicking on the menu item (Tools->User->1: Alternate). I can run it by making a button on the toolbar, but I was trying to automate the process with a script. Since the menu command worked I was trying “app.commandFromAction” but I was unable to get menu items working without your suggestion. Unfortunately, the following implementation also fails.

        app.getManagedAction("main/tools/user/alternate”).trigger()
        

        I tried "main/tools/user/1:alternate” as well but in both cases I am getting the syntax error “parse error backtrace”. Please let me know where I am going wrong. Thanks again.

        CL

        Edit for syntax typo

         
        Last edit: CLightfield 2014-08-01
        • Tim Hoffmann
          Tim Hoffmann
          2014-08-25

          Sorry for the late reply. The names of the user commands are currently not used for the associated managed actions. The actions are just numbered cmd0, cmd1, ... So you have to do

          app.getManagedAction("main/tools/user/cmd0").trigger()
          

          We might change that in the future to use command names.

           
  • CLightfield
    CLightfield
    2014-09-09

    Didn't think to try that. Works perfect. Thanks again Tim!