• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: .chk files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: .chk files


  • Subject: Re: .chk files
  • From: Paul Scott <email@hidden>
  • Date: Thu, 24 Jan 2008 18:23:27 -0800


On Jan 24, 2008, at 5:51 PM, Jordan Hadley wrote:

I have 2699 files with the filename extension .chk, and I'd like to change them all to .jpg.

Can anybody tell me what the code would be, or point me in the direction of a good tutorial that would apply to my situation?

Here's a script I wrote that changes (or adds) an extension to a file or list of files. If you save the script as an application or application bundle then you can either run it or drag and drop files to it. The script will ignore any files that would overwrite an existing file of with the new extension.


-- begin

on run
choose file with prompt "Choose files to process:" default location (path to desktop) with multiple selections allowed
set ListOfFiles to result as list
Process(ListOfFiles)
end run


on open parms
	set ListOfFiles to {}
	repeat with f in parms
		copy f to the end of ListOfFiles
	end repeat
	Process(ListOfFiles)
end open

on Process(parms)
set numChanged to 0
set numIgnored to 0
display dialog "Enter new extension:" default answer "jpg"
set newext to text returned of result
set newext to (do shell script "/bin/bash -c 'echo ${1#\\.}' -- " & quoted form of newext)
repeat with f in parms
set path1 to POSIX path of f
set fn to (do shell script "/bin/bash -c 'echo ${1%\\.*}' -- " & quoted form of path1)
set path2 to fn & "." & newext
set found to "0" is equal to (do shell script "test -e " & quoted form of path2 & ";echo $?")
if found then
set numIgnored to numIgnored + 1
else
do shell script "mv -n " & quoted form of path1 & " " & quoted form of path2 & " > /dev/null"
set numChanged to numChanged + 1
end if
end repeat
display dialog "Changed " & numChanged & ", Ignored " & numIgnored
end Process


-- end

I'm not claiming that this is the best way to do the job (I know shell scripting better than AS so I've used some shell shortcuts), but it's been working for me, and I appreciate the option of drag-and-drop or open dialog.

Paul

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >.chk files (From: "Jordan Hadley" <email@hidden>)

  • Prev by Date: Re: .chk files
  • Next by Date: Re: GUIscritpting, Pages and PDF
  • Previous by thread: Re: .chk files
  • Next by thread: Re: .chk files
  • Index(es):
    • Date
    • Thread