Skip to content

Instantly share code, notes, and snippets.

@dsumin
Created October 18, 2022 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsumin/294450fcfee07b719bc6686e641cdc21 to your computer and use it in GitHub Desktop.
Save dsumin/294450fcfee07b719bc6686e641cdc21 to your computer and use it in GitHub Desktop.
#!/usr/bin/osascript
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Set Selection as Desktop Picture
# @raycast.mode silent
# @raycast.packageName System
#
# Optional parameters:
# @raycast.icon 🖼️
#
# Documentation:
# @raycast.description Set selected item in Finder as Desktop Picture
# @raycast.author Dmitry Sumin
# @raycast.authorURL https://github.com/dsumin
tell application "Finder"
-- get Finder selected items
set selectedFiles to selection
end tell
if count of selectedFiles > 1 then
error "Too many files were selected in the Finder!"
end if
set pictureFile to item 1 of selectedFiles
set the fileExtension to the name extension of pictureFile
-- check that a JPG file is selected
if fileExtension = "jpg" or fileExtension = "jpeg"
-- Set as Desktop Picture
tell application "Finder"
set desktop picture to pictureFile
end tell
else
error "Selected item is not a jpeg file"
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment