2

I have an Automator Service entitled "Calculator" that is comprised of a single "Run AppleScript" action. It takes the selected text and then performs a calculation on this input text.

If the selected text is editable, I would like the Service to type the result. If the selected text is uneditable, I would like the Service to communicate the result via a dialog.

I know how to achieve these outcomes in AppleScript. I understand that my goal is entirely feasible if I set up two, separate Services. But, is there a way for my AppleScript-based Service to automatically determine whether the selected text is editable or not, so that I can add an if <selected text is editable> then statement?

  • 1
    You could try to replace the selected text with itself (same as copy/paste). If it works, the text is editable :-) – nohillside Mar 17 '17 at 7:48
  • I tried playing around with using try and on error but a paste failure didn't trigger the error with AXStaticText although it triggered the alert sound. I think you would have to ascertain which app has the text you selected and then determine if one of the properties of the selected text is AXStaticText or AXTextArea, the latter being editable. Looking at the System Events AppleScript Dictionary, I think that might be doable, although I haven't tried coding it. – user3439894 Mar 17 '17 at 15:45
  • I can't get the copy/paste method to work either. I am unfamiliar with the concept of AXStaticText. – rubik's sphere Mar 18 '17 at 0:25

You must log in to answer this question.

Browse other questions tagged .