I am trying to set the Desktop Wallpaper of my Mac(Running latest version of Catalina). But I keep getting this error message when trying to run my apple script.
error "System Events got an error: Can’t set file \"Library:Desktop Pictures:Ink Cloud.jpg:\" of current desktop to file \"Library:Desktop Pictures:Ink Cloud.jpg:\" of current desktop." number -10006 from file "Library:Desktop Pictures:Ink Cloud.jpg:" of current desktop
here is my code
tell application "System Events"
tell current desktop
set picture rotation to 0
set picture to file "Library:Desktop Pictures:Ink Cloud.jpg:"
end tell
end tell
I've been able to change all the other properties of the Desktop except the actual photo. I also tried using / for the file path. I have tried different file paths. But still not luck. Any help or advice would be greatly appreciated.
Running the code
tell application "System Events"
set currentPicturePath to picture of current desktop
end tell
reveals that the path is supposed to be a (slash separated) POSIX path
tell application "System Events"
tell current desktop
set picture rotation to 0
set picture to "/Library/Desktop Pictures/Ink Cloud.jpg"
end tell
end tell
Your (colon separated) HFS path contains two mistakes:
An HFS path (unlike the POSIX path) starts always with a disk name.
Only references to folders and packages have a trailing colon.
Related
I'm having trouble with the following line of AppleScript:
move file currentFile to POSIX file "/Users/UserName/Desktop/FolderName"
I've found that it works in one script but not in another, and I can't figure out why. In both scripts, currentFile is defined as an item in a list.
I've been trying different workarounds for hours but I can't get anything to work. Is there any reason why this code would work in one circumstance but not in another?
Thank you!
AppleScript doesn't know how to move a file.
It has to ask the Finder or System Events. In case of the Finder the syntax is pretty easy because the desktop folder of the current user is the root folder of the Finder
tell application "Finder"
move file currentFile to folder "FolderName"
end tell
currentFile must be an HFS path (colon separated).
In case of System Events the syntax is slightly different and System Events supports also POSIX paths
tell application "System Events"
move file currentFile to folder "FolderName" of desktop folder
end tell
I'm trying to do a very basic thing using Applescript but I'm having trouble. I am trying to create a very simple Applescript to just open a plain vanilla MP3 file on my desktop with QuickTime Player.
I want to use QuickTime and have it open so user can control it etc.
The basic problem is that the file name or folder path seems to be sometimes randomly causing problems especially when it has spaces in the name or the path folder names etc.
If I double click on any file they all open in QuickTime.
I created a very basic short audio file and saved it with a few different names like:
test1.mp3
test 1.mp3
this is a test.mp3
Then I created this very simple Applescript below.
generally = test1.mp3 will almost always open and start playing, however the other Versions with spaces in the title often produce and error (open thesong line fails i think) like:
The document “test1.mp3” could not be opened.
The file isn’t compatible with QuickTime Player.
error "QuickTime Player got an error: Can’t get document 1. Invalid index." number -1719 from document 1
think this is because it can't open the file.
Any help would be appreciated.
Applescript ...
tell application "Finder"
--varied attempts like this...
set thesong to "drive:Users:me:Desktop:music:test1.mp3" as string
set thesong to "drive:Users:me:Desktop:music:test1.mp3"
set thesong to "drive:Users:me:Desktop:music:this is an audio test.mp3" as string
set thesong to "drive:Users:me:Desktop:test1.mp3" as string
end tell
tell application "QuickTime Player"
activate
open thesong
play document 1
end tell
Also I tried adding delays thinking that QuickTime needed time to open before open / play song - but still have random fails...
tell application "QuickTime Player"
activate
delay 3
open thesong
delay 3
play document 1
end tell
The Finder is not needed and the delays are not needed either.
Assuming the file is on the desktop create a relative HFS path and add the alias keyword after the open command
set theSong to (path to desktop as text) & "test1.mp3"
tell application "QuickTime Player"
activate
set activeDocument to open alias theSong
play activeDocument
end tell
If the file is in the folder music on the desktop the path is
set theSong to (path to desktop as text) & "music:test1.mp3"
In AppleScript, there are differences between a string, a POSIX file («class furl») , and an alias.
When you do set thesong to "drive:Users:me:Desktop:music:test1.mp3" as string that creates a string, which is just plain text. QuickTime Player's open command requires either a POSIX file or an alias, which is why you get an error message (it doesn't know what to do with a plain text string).
While you ultimately need to end up with a POSIX file or alias, you can start with a string and then coerce it to the type you want.
Either of the open commands below should work:
set posixFile to "/Users/you/Desktop/file.mp3" as POSIX file
set aliasFile to ":Users:you:Desktop:file.mp3" as alias
tell app "QuickTime Player"
set theDoc to open posixFile
-- or set theDoc to open aliasFile
play theDoc
end tell
I'm new to AppleScript and not programmer, so I'm hoping someone can help me out...
I want to get the current track path in iTunes and open the file in another program [Riffstation]
seems like this should work, but it doesn't:
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Riffstation"
open songLocation
end tell
any help would be greatly appreciated!!!
Riffstation doesn't support AppleScript so you have to ask the Finder to open the file and pass it to Riffstation
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
If you want to ignore .m4p files use
tell application "iTunes" to set {location:songLocation, kind:songKind} to current track
if songKind is not "Protected AAC audio file" then
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
end if
How can I get the currently open file's path in photoshop (cs5) with applescript?
I'm using CS5 on Mac OSX 10.7
I've tried the answer below and it gives the following error in the Applescript Editor:
error "Adobe Photoshop CS5 got an error: Can’t get document 1.
Invalid index." number -1719 from document 1
UPDATE: I have tested the code below in CS5 and Mac OS 10.7 and can confirm that this works even with a simple switch of tell application "Adobe Photoshop CS4" to tell application "Adobe Photoshop CS5". The error that you are getting is the result of there either not being a document open in the first place since you are targeting document 1. You can easily check for this with the following:
tell application "Adobe Photoshop CS5"
set documentCount to count documents
if documentCount > 0 then
set theDocument to document 1
set theFilePath to file path of theDocument
return theFilePath
else
-- no documents open. what to do?
end if
end tell
OLD ANSWER: I don't have CS5 (yet), but here it is for CS4, and I imagine CS5's version won't be too different, if at all, since Adobe has done a good job normalizing the API since CS3:
tell application "Adobe Photoshop CS4"
set theDocument to document 1
set theFilePath to file path of theDocument
return theFilePath
end tell
--> Result: Macintosh HD:path:to:file:filename.ext
I am trying to save export setting of Quicktime movie to a file using AppleScript. This is my code:
set file2save to (choose file name default location (path to desktop) default name "setting.qtes")
tell application "QuickTime Player 7"
tell document "video.mov"
save export settings for QuickTime movie to file2save
end tell
end tell
But I get error "QuickTime Player 7 got an error: An error of type -2107 has occurred." number -2107
This error occurs on the "save export settings" line...
What am I doing wrong?
Thanks.
Here's the screenshot:
as far as I can tell the problem is that functions is no longer supported can't find anything regarding it in the dictionary
still wasn't working for me but I foundthis thread which looks like it may help
This works for me. You can see that I got the doc name from Quicktime to make sure it was correct, so your problem is with the document name. Note that if the movie is frontmost then you can also use terms like "tell first document".
set file2save to (choose file name default location (path to desktop) default name "setting.qtes")
tell application "QuickTime Player 7"
set docName to name of first document
tell document docName
save export settings for QuickTime movie to file2save
end tell
end tell