Home Apple applescript – Write an Apple Script to open Preview and carry out a process

applescript – Write an Apple Script to open Preview and carry out a process

0
applescript – Write an Apple Script to open Preview and carry out a process

There is not any have to contain Preview on this course of, though if that is actually the route you needed to go down, it is completely doable. Nevertheless, it would not sound like Preview is intrinsic to your wants, and there is a barely slicker technique of reaching the conversion:

property textual content merchandise delimiters : "."
-----------------------------------------------------------
# Ask the person to pick a .webp picture file, from which
# we extract the trail for its containing folder, and
# the title of the file
inform [choose file of type ("org.webmproject.webp") ¬
        with prompt "Select .webp Image File", "::"] ¬
        to inform {path:merchandise 1's POSIX path, folder:¬
        POSIX path of my alias named it} to set WebP ¬
        to it & {title:textual content (1 + (folder's size)) ¬
        via -1 of the trail}

# Create the JPEG's default file title by swapping
# out the ".webp" file extension for ".jpg", and 
# use the WebP's supply folder because the default JPEG
# vacation spot folder
inform the textual content objects of WebP's title to set [JPEG, ¬
        last item] to [{path:[WebP's folder, it] ¬
        , title:it}, "jpg"]

# Ask person to vacation spot folder and file title,
# which defaults to the supply folder and file title
# however with the ".jpg" file extension
inform (select file title default title "" & JPEG's title ¬
        default location WebP's folder with immediate ¬
        "Save .jpg Picture File As...") to set the trail ¬
        of the JPEG to the POSIX path

# Create the output file if it would not exist already
# and, in case it does, scrub its contents clear
shut entry (open for entry JPEG's path)
set eof of the trail of the JPEG to 0

# Learn within the unique .webp picture file as PNG
# picture information, and put this on the clipboard.
learn WebP's path as «class PNGf»
set the clipboard to the consequence

# Learn the clipboard contents, this time as JPEG
# picture information, and write this out to the output
# file path
get the clipboard as JPEG image
write the consequence to the JPEG's path as JPEG image

# Reveal the .jpeg picture file in Finder and
# concurrently deliver Finder to the foreground
inform software id "com.apple.finder" to activate ¬
        (reveal JPEG's «class ppth» as POSIX file)

I’ve used feedback within the script above to clarify every step of the method. However, broadly talking, it is requests the person to pick a .webp picture file, after which choose a vacation spot to avoid wasting the transformed .jpg. The .webp picture is learn into the system clipboard as information, which is then mutated into jpeg format, written out to a brand new file, and revealed in Finder.


Examined on macOS Sonoma 14.6 operating on an Apple M1 chip

LEAVE A REPLY

Please enter your comment!
Please enter your name here