Is there any way to listen to, and trigger actions when user right click and click change desktop background OR when the background image is actually changed on OSX?
You can get the current desktop image in the shell like this:
osascript -e 'tell app "finder" to get posix path of (get desktop picture as alias)'
I presume, if you really wanted to, you could create a launchd script with launchctl and a corresponding plist to check every minute or so to see if it has changed and then do something...
Related
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.
I'm trying to write a plugin for emacs that displays a notification using OS X's native notification display.
I've run into terminal-notifier which works, but it's a dependency that doesn't work on every mac. Plus the user should be made aware that they need to install the package.
What I want to do is call a process osascript -e and make it display the notification. The problem is, the only way to change its icon is from an external bundle. Is there any way to make osascript -e display what I want.
starting sudo osascript seems to do that, but it seems to be bad design and I also need to find a way to pass the root password every single time.
You cannot. This is simply not a macOS feature exposed to AppleScript.
If you need a custom icon, consider using a pop-up "dialog" rather than a Notification Center pop-up. With timeouts and buttons you can recreate much of the functionality, though not the integration nor aesthetics.
In `display dialog', if you wish to use the standard icons: 0, 1, or 2 (stop, note, or caution), perhaps don't have osascript be the program that displays the icon. Finder, for example:
osascript -e 'tell application "Finder"' -e 'activate' -e 'display dialog \
"this is the note icon." with icon note' -e 'end tell'
or without the tell application… you may use an icon of your choice by referencing it directly, e.g. the Terminal app's icon:
osascript -e 'display dialog "Terminal icon" with icon alias \
"Macintosh HD:Applications:Utilities:Terminal.app:Contents:Resources:Terminal.icns"'
I'm not sure what you mean by, "the only way to change its icon is from an external bundle. Is there any way to make osascript -e display what I want." What, precisely, do you want? What have you tried?
Here's the display dialog section from Apple's documentation.
Actually, this is possible.
Just save your script as an application and then switch the applet.icns file within the application's Contents/Resources folder for the icon you want.
Any notifications sent from your script will use that icon.
Unfortunately, the "display notification" documentation shows that you can't:
display notification
Posts a notification using the Notification Center, containing a title, subtitle, and explanation, and optionally playing a sound.
Syntax
display notification – text, required
with title – text, optional
subtitle – text, optional
sound name – text, optional
(Even using the tell application "..." trick from https://stackoverflow.com/a/49079025/3528 leaves you with the default notification icon.)
The reason why terminal-notifier can is because it's using the Notification Center APIs directly which, as far as I can tell, osascript doesn't present an interface to.
Best solution for was to:
Create an AppleScript app and replace the applet.icns file, inside the /Contents/Resources folder, with your icon file
create a handler:
on notify(vTxt, vTtl)
display notification vTxt with title vTtl
end notify
Don't forget to create an 'on idle' handler as well:
on idle
return 10
end idle
Save the app as "Stay open"
Run the app
now you can call the handler from another app or process and the notification will display with the icon of your app. Call it from the command line :
osascript -e 'tell application "MyApp" to notify("Message", "TITLE")'
I am looking for a tool that can 'stick' the OS X terminal app to the desktop background. I want it to be below the desktop icons, on top or instead of the background image.
I am using the terminal through out the day, from time to time. But I don't really need it for ongoing tasks, only to check something very fast. So having an active corner that shows the desktop would be the ideal guesture to reveal the terminal.
GeekTool has the ability to present the output of a terminal command on a desktop, however, I haven't been able to type something into the terminal overlay, GeekTool is showing. Is there any other tool, that could achieve that?
You can use the stock Script Editor app to save the following script as an application (.app file):
tell application "Terminal"
do script "cd ~/Desktop"
end tell
You can edit the script above to specify the directory you want the new window to use by default.
Once you've created your .app file you can put it on your desktop and conveniently double click it to open a new terminal window.
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.
Is there a way to obtain the current setting for desktop wallpaper change either using Apple Script or defaults read? Basically I want to know by looking at the plist file if the option of changing wallpaper every X minutes is enabled or not.
See the AppleScript dictionary for the Desktop Suite class of the System Events helper app. It contains the property:
picture rotation (integer) : never, using interval, using login, after sleep
There are separate values for each desktop, for instance, if you have more than one monitor active. For example:
tell application "System Events"
get picture rotation of its first desktop
end tell