Running on: MacOS Catalina 10.15.5
I made a Quick Action in Automator and it works just fine. In fact, I've been using it for a few years. The code in the action itself is not the problem, nor is it allowing accessibility/controls in system preferences. My problem is mind-boggling to say the least and I cannot seem to figure it out and thought I'd ask the hive mind.
After making my quick action with AppleScript and making sure the 'workflow receives: no input in any application' as I normal would do, then going in and assigning the shortcut the key 'F13' in System Preferences --> Keyboard --> Shortcuts --> Services, everything seems just great.
In the application I use this shortcut in, if I hover over the application main dropdown and hover over "Services" the item is there and has a shortcut 'F13' associated with it. If I select the shortcut from the dropdown menu, it works PERFECTLY.
Here is the problem, if I hit 'F13' on my keyboard, the service runs 3 times in a row. It's almost as if the system services thinks I want to run that particular item 3x. I have tried a number of different shortcut keys as well (as simple as: F13 and as complicated as: ⌘⌥⌃⇧N) and the shortcut keys did not yield any positive results either.
I have checked everywhere and cannot seem to find why this is happening. Any insight/help would be much appreciated. This is not an AppleScripting issue. It's something with the OS that is causing a triple selection on the services menu item for some reason. It does not seem to be a Key Repeater issue either.
Thanks in advance!
The problem, as best as I can tell, isn't that the workflow is running three times, but that you're getting a series of three security error messages. It seems that when you try to run a service using a keyboard shortcut, the system invokes an xpc service (com.automator.runner.xpc, which is located inside the automator application package), and that service is triggering security alerts because it doesn't have the accessibility rights that are needed for GUI scripting. There is no obvious way to grant the xpc the proper rights (and I suspect that would be an enormous security hole anyway), so that's not workable.
However, there's a workaround. Take your functioning script, copy it into a new Script Editor window, and save it as an application using the 'File Format' pulldown at the lower left of the save window:
Give this application permission to use accessibility features:
System Preferences → Security & Privacy → Privacy → Accessibility
Now create a service in automator that uses the Launch Application action to launch the script application you just created. Assign your keyboard shortcut to that service, and things should work as you like.
Of course, this launches an application, showing it in the Dock and grabbing the foreground momentarily, which can be visually distracting. If you want it to run silently in the background, do the following:
Right-click on the icon for the script app and choose Show Package Contents.
Drill down two levels to find the info.plist file, and open it in TextEdit, BBEdit or some other plain-text editor
Add the following key/value pair to the file (being carful not to break up other key/value groups):
<key>LSUIElement</key>
<true/>
Save the info.plist file, then run the app again; it should be faceless.
Related
I'm trying to use Automator to record an action on the system preferences, in the accessibility display pane. I want to change the value of the slider for the color filter intensity. (There are many similar questions asked here on SO, but they seem to be from 4-11 yr ago. I think the issue may be changes with Ventura, etc.)
I use automator to Watch Me Do and record the action. I reset the preferences manually. Clicking run does not cause the setting to change in preferences.
So I drag the actions from the Watch Me Do panel to the workflow timeline, which pop-out the action into an AppleScript. Running this is also not successful.
Can I manually set this preference in some way via the cli? When I search Apple developer docs, all I'm finding is Swift code to write an application. ((I realize that the app that will do this change, Automator, Terminal, or otherwise, will need to be granted accessibility permissions under privacy/security system preferences.))
Or how do I get/write an AppleScript to do this?
Also, I have checked the OSAX dictionary for System Preferences, and it does not have more specific controls registered besides at the basic window/pane/etc level
I want to use Automator and AppleScript to fill out a form in Safari. I have a functioning script that looks something like this toy example:
on run {}
tell application "System Events" to keystroke "Hello"
tell application "System Events" to keystroke tab
tell application "System Events" to keystroke "World"
end run
I wish to execute it with a keyboard shortcut when I'm at a specific point in my browser. However, when I do this, I run into permission issues:
The action "Run AppleSCript" encountered an error:
"System Events got an error: Automator Workflow Runner
(WorkflowServiceRunner, my_script_name) is not allowed to send keystrokes"
In System Prefrences -> Security & Privacy -> Privacy -> Accessibility I have allowed both Automator and AppleScript Utility, and under the Automation tab, I have allowed System Events for Safari.
I can get it to work, at least temporary, if I allow Safari in Accessibility too, but that seems to be too drastic and a security risk to have Safari to always have full control just to run a script from time to time.
How should I approach this? I want the script to be easy to use, and wouldn't want to go into the settings each time to temporary allow Safari. Or can this be automated too? Is there a completely different approach than Automator and AppleScript that would allow me to do this in a more user friendly and safe way? Basically, I want to do something similar to what AutoHotKey would be able to do in Windows.
I’m guessing that what you’ve done is set up a Quick Action and then given that Quick Action a shortcut under “Services” in “Keyboard:Shortcuts” in System Preferences. I was able to duplicate the problem by doing that: attempting to run the script requires that Safari itself have access to “control your computer”. If that is not what you’ve done, this solution should still work, but you may also want to update your question, in case a better solution is available.
What you can do is use redirection. Create an application that can be given permission to control your computer, and then create a Service that will launch the application.
Use Automator (or Script Editor) to create an Application with the above steps, adding as the first step tell application "Safari" to activate. You need that step because opening the app will take the focus away from Safari.
Save this Application. (If using Automator, you tell Automator that it’s an application when you start creating the script; if using Script Editor, you tell Script Editor that it’s an application when you save the script.)
Use Automator to create a Quick Action. Give it the action “Launch Application” and tell it to launch the application you just created.
Drag the application you created in step 2 into the “Accessibility” list in System Preferences’s “Security & Privacy” settings. (You may have to unlock those settings to allow changes.) It should be checked automatically when you drag it in, but if not you can check it.
In the “Services” list in the “Keyboard:Shortcuts” settings of System Preferences, the Quick Action you created in step 3 should be listed. Give it a keyboard shortcut.
At this point, you should be able to use the keyboard shortcut to run the application, and only that application needs to have permission to control your computer.
Normally user is doing it by clicking right-mouse into console title bar then selecting "edit" and finally "mark". -> http://www.megaleecher.net/Copy_Paste_Text_Dos_Window
So is there a way of doing it from a console application either by sending a message/api call/keyboard sequence to its own window ?
If this is your own application and you want the richer behaviour and flexibility of a windows app rather than a console app, then use a windows app. Otherwise, you can try to automate the steps by simulating the input via SendInput. I would advise against doing this because it requires two steps (once for right-click, once to select 'Mark'). This means if someone clicks something else between these two events, your sequence will be broken. Furthermore you are really relying on the automation of an implementation detail which is prone to change at any point.
Looking through the Console Functions, it doesn't appear as though anything exists for setting the selection. The closest is going the other way with GetConsoleSelectionInfo.
If you want to process the information that is within a console application, a better alternative is to pipe it to your own process and deal with it there.
Found: PostMessage(GetConsoleWindow(), WM_COMMAND, 65522, 0);
On a Mac, I'd like to have a keyboard shortcut to open Google Chrome. I know how to set a keyboard shortcut in the system preferences, however I'm unsure how to script it and hook it up.
Is this possible through AppleScript?
If you don't want to use any third party applications you need to create a service and assign it a shortcut.
Open Automator and select Service. You want it to look like the following :
Save it to its default location. ie ~/Library/Services
Open System Preferences --> Keyboard --> Keyboard Shortcuts. Enable the service and assign it a shortcut.
Shortcuts for Automator services might not always work until the service has been selected once from the menu bar. And they won't be available in applications that don't have a Services menu. There's usually also a noticable delay before they are run.
Using a third party application like Alfred or Apptivate would probably be a better idea.
Another option would be assign shortcuts to AppleScripts like this:
tell application "iTunes"
reopen
activate
end tell
Not with AppleScript alone -- there's no way to bind a keyboard shortcut to execute an arbitrary command.
Instead of writing something yourself, you may want to take a look at some existing launcher applications, like Butler, Spark, or Quicksilver.
Here is a trick.
Use Ctrl + ↑ to create a new desktop, say desktop2, and drag chrome application into that new desktop.
Open the keyboard preference pane, switch to the shortcut tab, and select mission control to assign a key to that desktop2. Now you can switch to chrome use that key.
I have a few different things open in the terminal whenever I'm developing -- log tailing, Ruby console, plain shell in a certain directory, and so on.
How do I:
start all those things at once, hopefully in the right position on the screen?
make them distinct so I can switch to them with Quicksilver / Alt-Tab?
Fluid solved this problem with all of my web apps, so now I want to do it with my terminals.
And while we're on the topic, has anyone found a working solution for getting OS X to remember window positions on an external monitor? If I unplug it and plug it back in, I have to drag everything back to the same position (although at least Mercury Mover makes it possible to do it with the keyboard.)
Open Terminal, and go into Preferences, then go into the settings tab, and create a new setting for each of your windows that you want. Either give them all different colour schemes, or duplicate a colour scheme multiple times for them all to have the same settings. Under the shell sub-tab, add "Run command" to be run at shell startup. (This is the command that will cd to the directory you want, or tail a log).
Then initialise the windows as you want. Then click Window in the main menu and select Save Windows as Group...
In OSX Yosemite you can use (in Terminal) Window -> Save group. It will do all the work for you.