• 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: Apply script to subfolders, save file to new folder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Apply script to subfolders, save file to new folder


  • Subject: Re: Apply script to subfolders, save file to new folder
  • From: Ruta <email@hidden>
  • Date: Thu, 4 Jan 2007 07:23:26 -0800 (PST)

Michelle,

Thank you very much for your advice.  I hope you will forgive my
continued questions.

1. Re the below: I am confused about what you're referring to by
"code".  If you're referring to some code in Photoshop that the
AppleScript is calling, there is none.  That is, I have made no
separate Photoshop code.  The AppleScript itself should be doing the
saving to a separate folder.  So, there is no code.  Given that answer,
is there a way to script saving a file to a new folder?

On Dec 22, 2006, at 8:52 AM, Ruta wrote:
Sorry my explanation was not clear.  Right now the script converts psd
files to jpg files and saves those jpg files to the same folder that
the psd files were in.  That is what the script is doing now.  It would
be much better for me, though, if the jpg files were saved to a
different folder.

Michelle: What I meant was if you provided the code you're using now to
save the files, it would help someone figure out what needs to be
changed.

-----------------

2. Thanks for the tip on Image Events.  Since this may be a cleaner way
to do what I want, I have found the below scripts on Apple's site, in
an attempt to start over.  They use Image Events.  One makes an action
apply to all files in a folder (though not subfolders); the second
converts image format for a single file.  However, despite my efforts,
I cannot merge them together and get them to work so that a batch of
image files will have their formats converted.  May I ask you to show
me how to merge them together?  And how can I further add "apply to
subfolders" and "save to separate folder" to the merged script?

Michelle: By the way, I think you can accomplish the same thing using
the Image Events suite in Applescript itself.

-----------------

Script for #1:

on resize(y)

	--get rid of .jpg or .jpeg at the end of file name
	if y ends with ".psd" then
		set new_y to (characters 1 thru -5 of y) as string
	else if y ends with ".tif" then
		set new_y to (characters 1 thru -5 of y) as string
	else if y ends with ".tiff" then
		set new_y to (characters 1 thru -6 of y) as string
	else
		set new_y to y
	end if

	set OFset to offset of "." in y
	if text OFset thru end of y is in {".psd", ".tif", ".tiff"} then set
new_y to text 1 through (OFset - 1) of y

	set new_y to new_y & ".jpg"

	if new_y does not end with ".jpg" then set new_y to new_y & ".jpg"

	tell application "Adobe Photoshop CS" --change as needed
		activate --if you want to watch PS do it's thing
		open file y
		set x to current document

		--get dimensions of current photo
		set w to width of x
		set h to height of x

		--calculate new dimensions based on longest side
		if w > h then
			set new_w to 1500
			set new_h to round (h * (1500 / w))
		else
			set new_h to 1500
			set new_w to round (w * (1500 / h))
		end if

		--resize current document
		resize image x width new_w height new_h

		--save it as a JPG file (.jpg)
		save current document in file new_y as JPEG appending no extension
		close current document

	end tell
end resize


set topLevel to (choose folder with prompt "Select folder of photos to
convert to jpg and resize. Subfolders will be included.")
splitFoldersFromFiles(topLevel)

on splitFoldersFromFiles(inputFolder)
	tell application "Finder"
		my processFiles(get files of inputFolder)
		set FolderList to folders of inputFolder
		repeat with thisFolder in FolderList
			my splitFoldersFromFiles(thisFolder)
		end repeat
	end tell
end splitFoldersFromFiles

on processFiles(FileList)
	repeat with thisFile in FileList
		my resize((thisFile) as string)
	end repeat
end processFiles

------------------

Script for #2 (Apply action to all files in a folder)

property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict",
"pct"}

tell application "Finder"
	activate
	try
		set the source_folder to choose folder with prompt "Pick a folder
containing the images to process:"
		set these_files to every file of the source_folder whose file type is
in the type_list or name extension is in the extension_list
		repeat with i from 1 to the count of these_files
			set this_path to (item i of these_files) as string
			tell application "Image Events"
				set this_image to open file this_path
				-- IMAGE PROCESSING STATEMENTS GO HERE
				close this_image
			end tell
			-- FINDER ACTIONS SUCH AS MOVE, DUPLICATE, OR DELETE GO HERE
		end repeat
	on error error_message
		display dialog error_message buttons {"OK"} default button 1
	end try
end tell

------------------

Script for #2 (Converts image format for a single file):

set this_file to choose file
try
	tell application "Image Events"
		launch
		-- get the parent folder of the image file
		set the parent_folder to the container of this_file
		-- derive new name for the new image file
		set the new_name to my add_extension(this_file, "tif")
		-- look for an existing file
		if (exists file new_name of the parent_folder) then
			error "A file named ¥"" & new_name & "¥" already exists."
		end if
		-- open the image file
		set this_image to open this_file
		-- save in new file. The result is a file ref to the new file
		set the new_image to save this_image as TIFF in file new_name of the
parent_folder with icon
		-- purge the open image data
		close this_image
	end tell
	tell application "Finder"
		-- delete the original file
		delete this_file
	end tell
on error error_message
	display dialog error_message
end try

on add_extension(this_file, new_extension)
	set this_info to the info for this_file
	set this_name to the name of this_info
	set this_extension to the name extension of this_info
	if this_extension is missing value then
		set the default_name to this_name
	else
		set the default_name to text 1 thru -((length of this_extension) + 2)
of this_name
	end if
	return (the default_name & "." & the new_extension)
end add_extension


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
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/mailman//archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Apply script to subfolders, save file to new folder
      • From: KOENIG Yvan <email@hidden>
  • Prev by Date: Re: Move based on content
  • Next by Date: Re: Apply script to subfolders, save file to new folder
  • Previous by thread: Re: Move based on content
  • Next by thread: Re: Apply script to subfolders, save file to new folder
  • Index(es):
    • Date
    • Thread