Tuesday, July 14, 2020

#1 2002-12-11 04:47:47 pm

Joe Bradfield
Member
From:: CA, USA
Registered: 2002-12-06
Posts: 192

Droplet to change to tif

I thought i could handle this on my own but i seem to have messed up something
I am trying to create a droplet that changesthe file name from xxx to xxx.tif
but only if there is no extension on the file

I can get the handler to work but how do i specify everything before the extension?

Applescript:

on open theFolder
   repeat with thisItem in theFolder
       tiffer(theFolder) of me
   end repeat
end open

on run
   tell application "Finder"
       display dialog ¬
           "This is a droplet." with icon 1 buttons {"Ok"} default button 1
   end tell
end run

on tiffer(theFolder)
   tell application "Finder"
       activate
       set theseFolderItems to every item in theFolder
       repeat with thisItem in theseFolderItems
           set thisitemname to the name of thisItem
           if name of thisItem does not end with ".tif" then
               set the name of thisItem to thisitemname & ".tif"
               --else
               
           end if
       end repeat
   end tell
end tiffer


Joe Bradfield
jbradfield@chemicon.com


Filed under: Finder

Offline

 

#2 2002-12-11 08:21:12 pm

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: Droplet to change to tif

I thought i could handle this on my own but i seem to have messed up something
I am trying to create a droplet that changesthe file name from xxx to xxx.tif
but only if there is no extension on the file

I can get the handler to work but how do i specify everything before the extension?


Does this work?

Applescript:

on open theFolder
   repeat with thisItem in theFolder
       tiffer(theFolder) of me
   end repeat
end open

on run
   tell application "Finder"
       display dialog ¬
           "This is a droplet." with icon 1 buttons {"Ok"} default button 1
   end tell
end run

on tiffer(theFolder)
   tell application "Finder"
       activate
       set theseFolderItems to every item in theFolder
       repeat with thisItem in theseFolderItems
           set thisitemname to the name of thisItem
           if thisitemname does not end with ".tif" then
               set the name of thisItem to thisitemname & ".tif"
               -- else do nothing because it ends in .tif
           end if
       end repeat
   end tell
end tiffer


Filed under: Finder

Offline

 

#3 2002-12-12 11:22:16 am

Joe Bradfield
Member
From:: CA, USA
Registered: 2002-12-06
Posts: 192

Re: Droplet to change to tif

i was able to get it to change before but the problem is it just adds the .tif to the file instead of replacing the old extension
in otherwords I "get xxx.jpg.tif"


Joe Bradfield
jbradfield@chemicon.com

Offline

 

#4 2002-12-12 11:54:40 am

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: Droplet to change to tif

i was able to get it to change before but the problem is it just adds the .tif to the file instead of replacing the old extension
in otherwords I "get xxx.jpg.tif"


I see. Well then, you might want to take a look at the information provided by the "info for" command in Standard Additions. Here are a few items that might be helpful in your current scenario.

Applescript:

set file_info to info for (choose file)

set displayed_name to displayed name of file_info -- name displayed by the Finder.
set extended_name to name of file_info -- file name plus extension (if extension is present).
set name_ext to name extension of file_info -- file extension only (if extension is present)
set ext_hidden to extension hidden of file_info -- Indicates if the file's extension is displayed in the Finder (if extension is present)

If it was my script, I'd probably use "info for" to gather information and Finder to modify the file name if needed, but I haven't checked to see if the Finder provides the same information. If it does, it would probably be better to use the Finder for all of it. :-)

Offline

 

#5 2002-12-12 01:29:37 pm

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: Droplet to change to tif

If it was my script, I'd probably use "info for" to gather information and Finder to modify the file name if needed, but I haven't checked to see if the Finder provides the same information. If it does, it would probably be better to use the Finder for all of it. :-)



Upon further investigation, I've found that the Finder provides all of the needed info. Maybe this will work as desired. I tested various elements of this but not the entire script.

Applescript:

on open theFolder
   repeat with thisItem in theFolder
      tiffer(theFolder) of me
   end repeat
end open

on run
   tell application "Finder"
      display dialog ¬
         "This is a droplet." with icon 1 buttons {"Ok"} default button 1
   end tell
end run

on tiffer(theFolder)
   
   set desired_extension to "tif" -- change this to work with other extensions
   
   tell application "Finder"

       activate
       set theseFolderItems to every item in theFolder
       
       repeat with a_file in theseFolderItems
           set file_extension to name extension of a_file
           set file_name to name of a_file
           set displayed_name to displayed name of a_file
           
           if file_extension is not desired_extension and ¬
               file_name does not end with ("." & desired_extension) and ¬
               displayed_name does not end with ("." & desired_extension) then ¬
               set name of a_file to (file_name & ("." & desired_extension))
       end repeat

   end tell

end tiffer


Filed under: Finder

Offline

 

#6 2002-12-12 01:41:39 pm

mgh
Member
Registered: 2002-12-07
Posts: 43
Website

Re: Droplet to change to tif

Rob beat me to the finish. The OSX finder allows retrieval of the part of a file name, the part without the extension. But I must ask: if a file is

myfile.jpg

then changing the extension to

myfile.tif

does not make the file a tif. Instead, it probably won't open. If you're changing ".jpg" files to ".tif" files you'll need Graphic Coverter.

Offline

 

#7 2002-12-12 03:32:11 pm

Joe Bradfield
Member
From:: CA, USA
Registered: 2002-12-06
Posts: 192

Re: Droplet to change to tif

I am generally using this script to change files with no extension to file.tif
but wanted the added feature of forcing the change on files that maybe named file.blah where blah is not neccesarily the extension just a bad habit in namming convention
thanks to all for their input


Joe Bradfield
jbradfield@chemicon.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)