Issue with MacOS script for opening application and clicking button if another app opens - applescript

I'm receiving the following error when trying to run my script, although I suspect there might be other issues than this immediate error. "system Events got an error: Can't get process "logitune".
I'm tryingto open LogiTune and click the first item under "my devices" if Zoom (app) is opened. Here is my script:
My apple script
And here is the LogiTune interface that I'm trying to manipulate:
LogiTune interface

Related

ARD - Setting Users Desktop Background to a file stored on clients desktop

Please can someone advise where i may be going wrong. I have copied a file called "ESSADB2020.png" to the clients desktop which succeeded. Now i'm trying to set that file to be the users desktop through a ARD unix command. Here is my code;
osascript -e 'tell application "Finder" to set desktop picture to "~/Desktop/ESSADB2020.png" as POSIX file'
Which retrieves the following error.
33:48: execution error: Finder got an error: AppleEvent handler failed. (-10000)
If there's a better way to do then, any suggestions are much appreciated thanks!
You can go to System Preferences -> Desktop and Screensaver -> Desktop. There is a pulldown menu that allows user to choose an image for a background. Click on the pulldown menu and select the file you want to use for a desktop picture.

AppleScript, why does first "display alert" work but then cause AppleScript icon to bounce, waiting for me to click it until I get another dialog?

NOTE: I do not have Admin privileges, and cannot use things that require assistance or accessibility or whatever it is!
I'm basically trying to write an execution of a script that sets up my macOS Desktop by opening apps, positioning them etc
Part of that is allowing me to click continue on a dialogue after doing certain things I have to do manually as a result of the limitation (positioning a few apps for example).
I can successfully have the first alert pop up, and when I press OK, it executes the task, but then the 2nd alert is hidden behind AppleScript and will not pop up until I click AppleScript. Anyone know why?
Heres what I have, and please keep in mind I do not have Admin privileges, which means I can't use System Events:
tell application "Script Editor"
set miniaturized of window 1 to true
end tell
display alert "App is opening. Make sure you log-out of Apple Connect!"
delay 3
tell application "Safari"
activate
make new document
set the bounds of the front window to {1077, 23, 1581, 464}
tell window 1
set URL of tab 1 to "http://appwebsite.com"
end tell
end tell
display alert "Set up App, sign into Apple then click OK to open all other Safari windows"
delay 1
tell application "Test Task App" to activate
Place an activate command before the display alert command so Script Editor has focus and the display alert command will not be hidden.
Example:
activate
display alert "Set up App, sign into Apple then click OK to open all other Safari windows"
You do not need it before the first one as Script Editor has focus with it runs the first display alert command, but once you activate Safari, the display alert command is behind Safari. So if you use an activate command before the display alert command, it brings it forward in front of, in this case, Safari.

Accessing an Applescript from 2 different menus produces different results. Why?

I've got an application that has an embedded Script menu for running Applescripts. However, if you try to run scripts with certain functions (mostly UI related) they won't work unless you run them from the System script menu (in menu bar).
For example, if in theApplication you say :
tell application "System Events" to tell application process "theApp" to get all windows
it will return an empty list if run from the program's script menu, but 2 if run from the system script menu. I've also tried:
tell application "System Events"
tell application process "theApp"
set allElements to UI elements
display dialog (count of allElements)
end tell
end tell
-- returns 2 when run from System script menu but 0 when run from within theApp.
Also if you run from the Script Editor it will work fine. GUI scripting is enabled for the application in System Preferences, so I'm curious as to why this is happening, and any workarounds for it (other than run the script from the System Script menu)? The Dictionary shows Standard Suite so it should have access to windows...
Any ideas?
I believe you haven't provisioned the app in question to use assistive devices.
You should really open System Preferences, then click the button for "Security", then unlock, and click the button for Assitive Devices, (the blue icon with a white man), then drag your app onto it (reveal your app from its Dock menu), and permit it to control your machine, remember to lock the pane afterwards.
I can not guaranttee this to work, but it is certainly worth a try.

Why does the safari app gets launched when I open apple script?

I have an applescript. The script goes like this..
tell application "Safari"
open location "http://www.google.com" -- mentions the perticular webpage to be loaded
activate --makes the Safari application the front most application
end tell
Whenever I open this script, the Safari application gets launched. To be very clear, I'm not running this application instead I am just opening this script in applescript editor.
Can anyone please explain me why the Safari is getting launched. The Safari gets launched but it will be hidden or say it does not put up any window. [Neither it does load any pages in the background, it just gets launched in the dock and a dot saying that the app is launched will be present].
Once I run the script then the safari puts up the window and loads the desired web-page.
Please Help.
In general, applescript must launch an application to learn what commands it understands. Over time applescript has gotten better at not launching applications for this task, but some apps still get launched. iPhoto is one I notice gets launched when I open applescripts that use it. As such it's not something you can avoid.
However, in your case there may be a fix. The "open location" command is a generic applescript command. You do not need to tell Safari to execute that command. Therefore you can probably change your script to this and avoid the launching issue. The open location command should just open the link in your default browser which I assume in your case is Safari. It should also automatically activate it for you.
Good luck.
open location "http://www.google.com"

OS X Mail - Open *.eml-files in compose mode

How can I open *.eml-files in compose mode for Mac OS X Mail? For Outlook "X-Unsent: 1" seems to do the trick, but does not work for Mac OS X Mail still opens in Read-Only.
This is a super old question, but obviously has received a fair number of views. My curiosity piqued, I figured I'd take a look. After some fiddling around, I found you can add the following header to make a message editable:
X-Uniform-Type-Identifier: com.apple.mail-draft
Add that to your otherwise RFC-2822 compliant message, give it a .eml or .emlx extension, and when you double-click it'll open as an editable message in Mail.app.
Have fun.
In macOS Catalina 10.15.7, running the following commands from a Python script worked to open a new message and then switch to compose mode, but there is a race condition between opening the message and putting it in Compose mode if the osascript command runs too quickly. The sleep command is there to prevent the race, but you may need to adjust the length of sleep time to compensate for this. (I also used time.sleep(1) in Python instead of the shell command.)
/usr/bin/open -a Mail path/to/tmp/message.eml
/bin/sleep 1
/usr/bin/osascript -e 'tell application "System Events" to tell application process "Mail"' -e 'keystroke "d" using {command down, shift down}' -e 'end tell'
Note that you must grant access to Terminal to control other apps, or the osascript command will fail with an error. To do that, open System Preferences, click on the Security & Privacy item, click Accessibility from the left menu, click the lock icon to unlock the menu, then check the Terminal item (or add it if not listed) in the "Allow apps to control your computer." list.
Also note that the Cmd-Shift-D keyboard shortcut sends a message that is already in compose mode, so if someone is using Mail at the time the script runs, and they have a separate compose window in the foreground, then the script could send that message instead of putting the new message in compose mode.

Resources