UI automation, appleScript Keyboard shortcuts for non-menued items Preview?












0















I am trying to create a keyboard shortcut action for Preview, namely Draw and Sketch. However, they are are the NON-menued items, which means can't get it done in System Preference I see someone done it from inspiration, it is possible, but when I try to follow alone, here is my code so far and please help me complete this. here are the action. enter image description here



Here is the error I am facing nowenter image description here



after some researches, does the UI/accessibility inspector UI inspector help?



activate application "Preview"
delay 0.4
set the menuItem to "Draw"
tell application "System Events"
try
tell application process "Preview" to click radio button menuItem of radio group 1 of splitter group 1 of window 1
on error
try
tell application process "Preview" to click radio button menuItem of radio group 1 of window 1
on error errorM

display dialog errorM

end try
end try
end tell


ideally, trying to make it to work when all bars are hidden,
but if not possible. can we make it to work vwith mark up bar is shown. as below.



enter image description here










share|improve this question





























    0















    I am trying to create a keyboard shortcut action for Preview, namely Draw and Sketch. However, they are are the NON-menued items, which means can't get it done in System Preference I see someone done it from inspiration, it is possible, but when I try to follow alone, here is my code so far and please help me complete this. here are the action. enter image description here



    Here is the error I am facing nowenter image description here



    after some researches, does the UI/accessibility inspector UI inspector help?



    activate application "Preview"
    delay 0.4
    set the menuItem to "Draw"
    tell application "System Events"
    try
    tell application process "Preview" to click radio button menuItem of radio group 1 of splitter group 1 of window 1
    on error
    try
    tell application process "Preview" to click radio button menuItem of radio group 1 of window 1
    on error errorM

    display dialog errorM

    end try
    end try
    end tell


    ideally, trying to make it to work when all bars are hidden,
    but if not possible. can we make it to work vwith mark up bar is shown. as below.



    enter image description here










    share|improve this question



























      0












      0








      0


      2






      I am trying to create a keyboard shortcut action for Preview, namely Draw and Sketch. However, they are are the NON-menued items, which means can't get it done in System Preference I see someone done it from inspiration, it is possible, but when I try to follow alone, here is my code so far and please help me complete this. here are the action. enter image description here



      Here is the error I am facing nowenter image description here



      after some researches, does the UI/accessibility inspector UI inspector help?



      activate application "Preview"
      delay 0.4
      set the menuItem to "Draw"
      tell application "System Events"
      try
      tell application process "Preview" to click radio button menuItem of radio group 1 of splitter group 1 of window 1
      on error
      try
      tell application process "Preview" to click radio button menuItem of radio group 1 of window 1
      on error errorM

      display dialog errorM

      end try
      end try
      end tell


      ideally, trying to make it to work when all bars are hidden,
      but if not possible. can we make it to work vwith mark up bar is shown. as below.



      enter image description here










      share|improve this question
















      I am trying to create a keyboard shortcut action for Preview, namely Draw and Sketch. However, they are are the NON-menued items, which means can't get it done in System Preference I see someone done it from inspiration, it is possible, but when I try to follow alone, here is my code so far and please help me complete this. here are the action. enter image description here



      Here is the error I am facing nowenter image description here



      after some researches, does the UI/accessibility inspector UI inspector help?



      activate application "Preview"
      delay 0.4
      set the menuItem to "Draw"
      tell application "System Events"
      try
      tell application process "Preview" to click radio button menuItem of radio group 1 of splitter group 1 of window 1
      on error
      try
      tell application process "Preview" to click radio button menuItem of radio group 1 of window 1
      on error errorM

      display dialog errorM

      end try
      end try
      end tell


      ideally, trying to make it to work when all bars are hidden,
      but if not possible. can we make it to work vwith mark up bar is shown. as below.



      enter image description here







      applescript ui-automation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 18 at 20:55







      user3096996

















      asked Jan 18 at 20:04









      user3096996user3096996

      4119




      4119
























          1 Answer
          1






          active

          oldest

          votes


















          0














          This work for me using the latest version of macOS Mojave



          tell application "Preview" to activate
          repeat while application "Preview" is not running
          delay 0.2
          end repeat
          tell application "System Events"
          try
          click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          try
          click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
          delay 0.2
          end repeat
          set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
          set theCheckboxes to description of description2

          if item 1 of theCheckboxes is "Draw" then
          set checkBoxDraw to 1
          else
          set checkBoxDraw to 2
          end if
          if item 1 of theCheckboxes is "Sketch" then
          set checkBoxSketch to 1
          else
          set checkBoxSketch to 2
          end if
          delay 1
          -- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
          click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
          end tell
          -- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
          tell application "Preview" to tell window 1
          set visible to false
          set visible to true
          end tell
          delay 3





          share|improve this answer


























          • How should we locate the UI element systematically ? Is there a way to list all UI element of an application?

            – user3096996
            Jan 18 at 20:36











          • unfortunately, the code does't work for me.

            – user3096996
            Jan 18 at 20:40











          • can you please try again when the layout that posted, I forgot the default layout, otherwise, will try it myself. or you can post the layout that work for you, will run again after matching the working layout.

            – user3096996
            Jan 18 at 20:57











          • @ch1zpink, Thank you for updating the code. Maybe I am doing it wrong from Automator from the beginning. You code run without error but still don't accomplish the task, choosing the Draw as the current tool.

            – user3096996
            Jan 19 at 0:26











          • Posted a completely new version.. Try running that in script editor app.... Curious to see if you will still get errors

            – wch1zpink
            Jan 19 at 3:24











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54260738%2fui-automation-applescript-keyboard-shortcuts-for-non-menued-items-preview%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          This work for me using the latest version of macOS Mojave



          tell application "Preview" to activate
          repeat while application "Preview" is not running
          delay 0.2
          end repeat
          tell application "System Events"
          try
          click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          try
          click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
          delay 0.2
          end repeat
          set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
          set theCheckboxes to description of description2

          if item 1 of theCheckboxes is "Draw" then
          set checkBoxDraw to 1
          else
          set checkBoxDraw to 2
          end if
          if item 1 of theCheckboxes is "Sketch" then
          set checkBoxSketch to 1
          else
          set checkBoxSketch to 2
          end if
          delay 1
          -- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
          click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
          end tell
          -- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
          tell application "Preview" to tell window 1
          set visible to false
          set visible to true
          end tell
          delay 3





          share|improve this answer


























          • How should we locate the UI element systematically ? Is there a way to list all UI element of an application?

            – user3096996
            Jan 18 at 20:36











          • unfortunately, the code does't work for me.

            – user3096996
            Jan 18 at 20:40











          • can you please try again when the layout that posted, I forgot the default layout, otherwise, will try it myself. or you can post the layout that work for you, will run again after matching the working layout.

            – user3096996
            Jan 18 at 20:57











          • @ch1zpink, Thank you for updating the code. Maybe I am doing it wrong from Automator from the beginning. You code run without error but still don't accomplish the task, choosing the Draw as the current tool.

            – user3096996
            Jan 19 at 0:26











          • Posted a completely new version.. Try running that in script editor app.... Curious to see if you will still get errors

            – wch1zpink
            Jan 19 at 3:24
















          0














          This work for me using the latest version of macOS Mojave



          tell application "Preview" to activate
          repeat while application "Preview" is not running
          delay 0.2
          end repeat
          tell application "System Events"
          try
          click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          try
          click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
          delay 0.2
          end repeat
          set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
          set theCheckboxes to description of description2

          if item 1 of theCheckboxes is "Draw" then
          set checkBoxDraw to 1
          else
          set checkBoxDraw to 2
          end if
          if item 1 of theCheckboxes is "Sketch" then
          set checkBoxSketch to 1
          else
          set checkBoxSketch to 2
          end if
          delay 1
          -- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
          click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
          end tell
          -- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
          tell application "Preview" to tell window 1
          set visible to false
          set visible to true
          end tell
          delay 3





          share|improve this answer


























          • How should we locate the UI element systematically ? Is there a way to list all UI element of an application?

            – user3096996
            Jan 18 at 20:36











          • unfortunately, the code does't work for me.

            – user3096996
            Jan 18 at 20:40











          • can you please try again when the layout that posted, I forgot the default layout, otherwise, will try it myself. or you can post the layout that work for you, will run again after matching the working layout.

            – user3096996
            Jan 18 at 20:57











          • @ch1zpink, Thank you for updating the code. Maybe I am doing it wrong from Automator from the beginning. You code run without error but still don't accomplish the task, choosing the Draw as the current tool.

            – user3096996
            Jan 19 at 0:26











          • Posted a completely new version.. Try running that in script editor app.... Curious to see if you will still get errors

            – wch1zpink
            Jan 19 at 3:24














          0












          0








          0







          This work for me using the latest version of macOS Mojave



          tell application "Preview" to activate
          repeat while application "Preview" is not running
          delay 0.2
          end repeat
          tell application "System Events"
          try
          click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          try
          click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
          delay 0.2
          end repeat
          set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
          set theCheckboxes to description of description2

          if item 1 of theCheckboxes is "Draw" then
          set checkBoxDraw to 1
          else
          set checkBoxDraw to 2
          end if
          if item 1 of theCheckboxes is "Sketch" then
          set checkBoxSketch to 1
          else
          set checkBoxSketch to 2
          end if
          delay 1
          -- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
          click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
          end tell
          -- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
          tell application "Preview" to tell window 1
          set visible to false
          set visible to true
          end tell
          delay 3





          share|improve this answer















          This work for me using the latest version of macOS Mojave



          tell application "Preview" to activate
          repeat while application "Preview" is not running
          delay 0.2
          end repeat
          tell application "System Events"
          try
          click menu item "Show Markup Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          try
          click menu item "Show Toolbar" of menu 1 of menu bar item "View" of menu bar 1 of application process "Preview"
          end try
          delay 0.5
          repeat while not (exists of toolbar 1 of window 1 of application process "Preview")
          delay 0.2
          end repeat
          set description2 to a reference to every checkbox of toolbar 1 of window 1 of application process "Preview"
          set theCheckboxes to description of description2

          if item 1 of theCheckboxes is "Draw" then
          set checkBoxDraw to 1
          else
          set checkBoxDraw to 2
          end if
          if item 1 of theCheckboxes is "Sketch" then
          set checkBoxSketch to 1
          else
          set checkBoxSketch to 2
          end if
          delay 1
          -- Below, insert either checkBoxSketch for "Sketch" or checkBoxDraw for "Draw"
          click checkbox checkBoxDraw of toolbar 1 of window 1 of application process "Preview"
          end tell
          -- without these next following lines, the toolbar "Draw" or "Sketch" do not appear to be selected
          tell application "Preview" to tell window 1
          set visible to false
          set visible to true
          end tell
          delay 3






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 19 at 3:22

























          answered Jan 18 at 20:33









          wch1zpinkwch1zpink

          1,1811414




          1,1811414













          • How should we locate the UI element systematically ? Is there a way to list all UI element of an application?

            – user3096996
            Jan 18 at 20:36











          • unfortunately, the code does't work for me.

            – user3096996
            Jan 18 at 20:40











          • can you please try again when the layout that posted, I forgot the default layout, otherwise, will try it myself. or you can post the layout that work for you, will run again after matching the working layout.

            – user3096996
            Jan 18 at 20:57











          • @ch1zpink, Thank you for updating the code. Maybe I am doing it wrong from Automator from the beginning. You code run without error but still don't accomplish the task, choosing the Draw as the current tool.

            – user3096996
            Jan 19 at 0:26











          • Posted a completely new version.. Try running that in script editor app.... Curious to see if you will still get errors

            – wch1zpink
            Jan 19 at 3:24



















          • How should we locate the UI element systematically ? Is there a way to list all UI element of an application?

            – user3096996
            Jan 18 at 20:36











          • unfortunately, the code does't work for me.

            – user3096996
            Jan 18 at 20:40











          • can you please try again when the layout that posted, I forgot the default layout, otherwise, will try it myself. or you can post the layout that work for you, will run again after matching the working layout.

            – user3096996
            Jan 18 at 20:57











          • @ch1zpink, Thank you for updating the code. Maybe I am doing it wrong from Automator from the beginning. You code run without error but still don't accomplish the task, choosing the Draw as the current tool.

            – user3096996
            Jan 19 at 0:26











          • Posted a completely new version.. Try running that in script editor app.... Curious to see if you will still get errors

            – wch1zpink
            Jan 19 at 3:24

















          How should we locate the UI element systematically ? Is there a way to list all UI element of an application?

          – user3096996
          Jan 18 at 20:36





          How should we locate the UI element systematically ? Is there a way to list all UI element of an application?

          – user3096996
          Jan 18 at 20:36













          unfortunately, the code does't work for me.

          – user3096996
          Jan 18 at 20:40





          unfortunately, the code does't work for me.

          – user3096996
          Jan 18 at 20:40













          can you please try again when the layout that posted, I forgot the default layout, otherwise, will try it myself. or you can post the layout that work for you, will run again after matching the working layout.

          – user3096996
          Jan 18 at 20:57





          can you please try again when the layout that posted, I forgot the default layout, otherwise, will try it myself. or you can post the layout that work for you, will run again after matching the working layout.

          – user3096996
          Jan 18 at 20:57













          @ch1zpink, Thank you for updating the code. Maybe I am doing it wrong from Automator from the beginning. You code run without error but still don't accomplish the task, choosing the Draw as the current tool.

          – user3096996
          Jan 19 at 0:26





          @ch1zpink, Thank you for updating the code. Maybe I am doing it wrong from Automator from the beginning. You code run without error but still don't accomplish the task, choosing the Draw as the current tool.

          – user3096996
          Jan 19 at 0:26













          Posted a completely new version.. Try running that in script editor app.... Curious to see if you will still get errors

          – wch1zpink
          Jan 19 at 3:24





          Posted a completely new version.. Try running that in script editor app.... Curious to see if you will still get errors

          – wch1zpink
          Jan 19 at 3:24


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54260738%2fui-automation-applescript-keyboard-shortcuts-for-non-menued-items-preview%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Callistus III

          Plistias Cous

          Index Sanctorum