Monday, September 16, 2019

#1 2019-04-23 08:25:00 am

CamSox
Member
Registered: 2016-12-22
Posts: 9

Change File Extension of Dropped Items

Hello all,
I am trying to make a script that allows you to change the file extension of an item (pictures in this case), but I keep on getting the error:

Can’t set «class extn» of alias to "jpg".
System Events got an error: Can’t set name extension of alias to "jpg". (-10006)

Here is my code so far:

Applescript:

on open droppedItems
   repeat with a from 1 to count of droppedItems
       set currentItem to item a of droppedItems
       tell application "System Events"
           set itemExtension to the name extension of currentItem
       end tell
       
       
       set displayOptions to choose from list {".jpg", ".png", ".tiff", ".pdf"}
       if ".jpg" is in displayOptions then
           tell application "System Events"
               set the name extension of currentItem to "jpg"
           end tell
       end if
       
   end repeat
end open

Thank you in advance for any help, it would be greatly appreciated.

-CamSox

Last edited by CamSox (2019-04-23 08:25:19 am)

Offline

 

#2 2019-04-23 08:51:38 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 519

Re: Change File Extension of Dropped Items

name extension in "System Events" is read-only property. You must use "Finder" instead

Applescript:


open {choose file of type {"public.image"}} --this code line I add only to test dropplet--remove it or comment for real dropplet

on open droppedItems
   repeat with a from 1 to count of droppedItems
       set currentItem to item a of droppedItems
       set displayOptions to choose from list {".jpg", ".png", ".tiff", ".pdf"}
       if ".jpg" is in displayOptions then tell application "Finder" to set the name extension of currentItem to "jpg"
   end repeat
end open

Note: If your goal is to standardize the extensions of all image files, then there is a better way than this droplet: using Uniform Type Identifiers (named UTI, all image files has UTI "public.image")

Last edited by KniazidisR (2019-04-23 09:48:51 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

#3 2019-04-23 10:10:03 am

CamSox
Member
Registered: 2016-12-22
Posts: 9

Re: Change File Extension of Dropped Items

Thank you so much KniazidisR, much appreciated!

Offline

 

#4 2019-04-24 07:14:18 am

CK
Member
From:: UK
Registered: 2018-11-04
Posts: 97

Re: Change File Extension of Dropped Items

KniazidisR wrote:

Applescript:


open {choose file of type {"public.image"}}

using Uniform Type Identifiers (named UTI, all image files has UTI "public.image")


Nice tip!  Logging this one for future use.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)