You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript Commands

Questions:


How do I copy and paste using Applescript?

How do I select something using Applescript?

How do I set values to something, like a text field, using Applescript?

How do I click on a pop-up button using Applescript, and how do I open floating windows using Applescript?

MacBook Air 13″, macOS 11.1

Posted on Jan 22, 2022 3:50 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 24, 2022 1:27 PM

Although I usually hate second-guessing why people want to do specific things, I have to ask why here.


AppleScript is not geared to emulating user actions. It can do that, but there are many, many gotchas in doing that, not least that things can move around on screen, so just because you think you know where something is (because that's where it was when you wrote the script), that doesn't mean it's in the same place when you come to run the script later on.


There are some ways to mitigate this, but the right approach depends on knowing a fair bit about the environment - and if you're trying to do this globally (i.e. in any application) then you may have an uphill battle.


> How do I copy and paste using Applescript?


There's also no quicker way to 'copy and paste' than Command-C and Command-V, hence the question of what it is you're trying to do here.


> How do I select something using Applescript?


This is application specific. Not all applications support the concept of 'selecting', and there are different ways of selecting things - a text based application will work differently from a web browser, from a photos app, etc., etc.


> How do I set values to something, like a text field, using Applescript?


You first need some way to identify the text field you want to manipulate. This is 100% application specific.


> How do I click on a pop-up button using Applescript, and how do I open floating windows using Applescript?


Two different actions. Clicking a pop-up button involves emulating user actions (move the mouse, click, drag, etc.) which is cumbersome to script. A better option would be to manipulate the button directly, but you need to know more about the app in question to do this.


For pop-up windows, raw AppleScript can post a dialog or a notification window, and that's it. If you want a richer user interface (buttons, text, images, etc.) then you need to step up to something richer.


That's not to say that what you are asking isn't possible, just that you need to be more specific about what you're trying to do, and there may be better 'AppleScript-y' ways to do it.


2 replies
Question marked as Top-ranking reply

Jan 24, 2022 1:27 PM in response to mistermusicman93

Although I usually hate second-guessing why people want to do specific things, I have to ask why here.


AppleScript is not geared to emulating user actions. It can do that, but there are many, many gotchas in doing that, not least that things can move around on screen, so just because you think you know where something is (because that's where it was when you wrote the script), that doesn't mean it's in the same place when you come to run the script later on.


There are some ways to mitigate this, but the right approach depends on knowing a fair bit about the environment - and if you're trying to do this globally (i.e. in any application) then you may have an uphill battle.


> How do I copy and paste using Applescript?


There's also no quicker way to 'copy and paste' than Command-C and Command-V, hence the question of what it is you're trying to do here.


> How do I select something using Applescript?


This is application specific. Not all applications support the concept of 'selecting', and there are different ways of selecting things - a text based application will work differently from a web browser, from a photos app, etc., etc.


> How do I set values to something, like a text field, using Applescript?


You first need some way to identify the text field you want to manipulate. This is 100% application specific.


> How do I click on a pop-up button using Applescript, and how do I open floating windows using Applescript?


Two different actions. Clicking a pop-up button involves emulating user actions (move the mouse, click, drag, etc.) which is cumbersome to script. A better option would be to manipulate the button directly, but you need to know more about the app in question to do this.


For pop-up windows, raw AppleScript can post a dialog or a notification window, and that's it. If you want a richer user interface (buttons, text, images, etc.) then you need to step up to something richer.


That's not to say that what you are asking isn't possible, just that you need to be more specific about what you're trying to do, and there may be better 'AppleScript-y' ways to do it.


Applescript Commands

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.