Here's my best solution: Create an Applescript with:
do shell script "/Applications/Firefox.app/Contents/MacOS/firefox -P default -no-remote & killall Firefox.app"
And save it as an application.
You can put whatever application with whatever args in the first part. The part after the &
needs to kill whatever you have named your script + .app. You'll see the script app flash up in the dock, but it will then disappear.
Note: The script will not work properly when run from Script Editor, only when run from the script application you have created.
If the button is not available directly, you might have to guess.
What works in High Sierra is:
tell application "System Events"
tell process "Image Capture"
click button "Scan" of group 2 of splitter group 1 of window "Image Capture"
end tell
end tell
On older macOS releases, group 1
may have to be used.
Another workaround would be to activate the window and press the space bar:
tell application "Image Capture"
activate
tell application "System Events" to key code 49
end tell
You can actually try to near it down by running commands like:
UI elements of window 1
UI elements of splitter group 1 of window 1
UI elements of group 1 of splitter group 1 of window 1
or, as @Lri said in the comments:
properties of UI elements of window 1
properties of UI elements of UI elements of window 1
This will present you with a list of elements contained, and you can guess your way from there.
Best Answer
Make a new Service using Automator.
Add your AppleScript:
Make a keyboard shortcut using System Preferences:
Keyboard shortcuts will work across applications.