ASObjC_Explorer_4 and existing scripts

Hi all!

I have try to modify and run my old scripts (lake that) with ASObjC_Explorer_4 (from Shane Stanley).
But i don’t understand how do it…
What i should write in left (calling script) and right (main script) windows for that?


using terms from application "ASObjC Runner-N" -- needed to compile script
	(* ======== Общие переменные для растровых и векторных типов файлов ======== *)
	-- Raster images files formats
	property rasterTypeList : {"8BPS", "8BPB", "TIFF", "PNGf"}
	property rasterExtensionList : {"psd", "psb", "tif", "tiff", "png"}
	property rasterTypeIDsList : {"public.png", "com.adobe.photoshop-image", "dyn.ah62d4rv4ge81a65c", "public.tiff"}
	
	-- Vector images files formats
	property vectorTypeList : {"EPSP", "PDF"}
	property vectorExtensionList : {"ai", "eps", "pdf"}
	property vectorTypeIDsList : {"com.adobe.illustrator.ai-image", "com.adobe.encapsulated-postscript", "com.adobe.pdf"}
	
	property outputFolder : missing value -- путь для сохранения превью файлов
	property inputFolder : missing value -- путь для загрузки оригинальных файлов	
	property previewResolution : missing value
	property previewSize : missing value
	property previewQuality : missing value
	
	global filesCounter -- счетчик обработанных файлов
	global validFiles -- счетчик поддерживаемых файлов
	
	property vectorFilesName : {}
	property rasterFilesName : {}
	property containerVectorFiles : {}
	property containerRasterFiles : {}
	
	property myTitle : "Convert to JPEG"
	property buttonCancel : "Cancel" as text
	property buttonOk : " Ok " as text
	property buttonRepeat : "Repeat" as text
	property buttonContinue : "Continue" as text
	
	property runnerPath : "" -- get path to bundled copy, in this case directly in the Resources folder
	
	
	on open droppeditems
		
		set mySelf to path to me as text # ADDED
		if runnerPath does not start with mySelf then set runnerPath to "" # ADDED
		set runnerPath to (path to resource "ASObjC Runner-N.app") as text
		
		my setFilesList(droppeditems)
		
		---------------------------
		set vectorFilesCount to the count of the vectorFilesName
		set rasterFilesCount to the count of the rasterFilesName
		
		if vectorFilesCount < 1 and rasterFilesCount < 1 then
			my unsupportedFormat() -- select nothing 
			return
		end if
		---------------------------
		
		try
			set outputFolder to (choose folder with prompt "Choose folder for JPEG files:") as string -- choose folder to save
		on error
			tell me
				activate
				display alert ¬
					"Sorry, an error has occured" message ¬
					"Was an incorrect values for the Output Folder." buttons {buttonCancel} default button 1
			end tell
			return
		end try
		
		repeat with aFile from 1 to the count of vectorFilesName
			try
				tell application runnerPath
					parsed path aFile
					set pathComponents to path components of (parsed path aFile) as list
					set fileContainer to containing item of (parsed path aFile)
					set shortFileName to name stub of (parsed path aFile)
					set fullFileName to name of (parsed path aFile)
					set nameExtension to name extension of (parsed path aFile)
				end tell
			on error the error_message number the error_number
				tell me
					activate
					display alert ¬
						"Sorry, an error has occured" & the error_number & ". " & the error_message ¬
						buttons {buttonCancel} default button 1
				end tell
			end try
			
			tell me
				activate
				try
					display dialog ¬
						"Компонеты пути “ " & pathComponents & return & return & ¬
						"Контейнер “ " & fileContainer
				on error the error_message number the error_number
					tell me
						activate
						display alert ¬
							"Sorry, an error has occured" & the error_number & ". " & the error_message ¬
							buttons {buttonCancel} default button 1
					end tell
				end try
			end tell
		end repeat
		
	end open
	
	-- This droplet processes files dropped onto the applet 
	on setFilesList(these_items)
		set vectorFilesName to {}
		set rasterFilesName to {}
		set containerVectorFiles to {}
		set containerRasterFiles to {}
		
		repeat with i from 1 to the count of these_items
			set this_item to alias (item i of these_items)
			set the item_info to info for this_item
			if folder of the item_info is true then
				set levelOfInsert to 1
				process_folder(this_item)
			else
				try
					set this_extension to the name extension of item_info
				on error
					set this_extension to ""
				end try
				try
					set this_filetype to the file type of item_info
				on error
					set this_filetype to ""
				end try
				try
					set this_typeID to the type identifier of item_info
				on error
					set this_typeID to ""
				end try
				
				--------------------------------------
				-- verify file types, and separate it to vector and raster
				--------------------------------------
				if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the vectorTypeList) or (this_extension is in the vectorExtensionList) or (this_typeID is in vectorTypeIDsList)) then
					copy this_item to end of vectorFilesName
				else if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the rasterTypeList) or (this_extension is in the rasterExtensionList) or (this_typeID is in rasterTypeIDsList)) then
					copy this_item to end of rasterFilesName
				end if
				--------------------------------------
				
			end if
		end repeat
		return
	end setFilesList
	
	-- this sub-routine processes folders 
	on process_folder(this_folder)
		set these_items to list folder this_folder without invisibles
		repeat with i from 1 to the count of these_items
			set this_item to alias ((this_folder as text) & (item i of these_items))
			set the item_info to info for this_item
			if folder of the item_info is true then
				set levelOfInsert to levelOfInsert + 1
				process_folder(this_item)
			else
				try
					set this_extension to the name extension of item_info
				on error
					set this_extension to ""
				end try
				try
					set this_filetype to the file type of item_info
				on error
					set this_filetype to ""
				end try
				try
					set this_typeID to the type identifier of item_info
				on error
					set this_typeID to ""
				end try
				--------------------------------------
				-- verify file types, and separate it to vector and raster
				--------------------------------------
				if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the vectorTypeList) or (this_extension is in the vectorExtensionList) or (this_typeID is in vectorTypeIDsList)) then
					copy this_item to end of vectorFilesName
				else if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the rasterTypeList) or (this_extension is in the rasterExtensionList) or (this_typeID is in rasterTypeIDsList)) then
					copy this_item to end of rasterFilesName
				end if
				--------------------------------------
			end if
		end repeat
		return
	end process_folder
	
	(*===== Нет поддерживаемых файлов =====*)
	on unsupportedFormat()
		tell me
			activate
			display dialog ¬
				"You do not select any files" & return & "or file type is not supported" buttons {buttonCancel} default button 1 with title myTitle with icon stop
		end tell
		return
	end unsupportedFormat
end using terms from

best regards, Alex.

Alex,

Here are the scripts I sent you in reply to your email. They use ASObjC code instead of ASObjC Runner, which I presume is what you want to do. They should give you an idea of how to proceed.

Here’s the calling script:

property vectorFilePosixPaths : {} -- will contain vector POSIX paths
property rasterFilePosixPaths : {} -- will contain raster POSIX paths

-- this is just for testing
open (choose folder with multiple selections allowed)

on open droppeditems
	tell script "^"
		repeat with i from 1 to count of droppeditems
			(its collectFromItem:(POSIX path of (item i of droppeditems)) vectorFiles:vectorFilePosixPaths rasterFiles:rasterFilePosixPaths)
		end repeat
		-- at this stage you have the two lists of paths
		log vectorFilePosixPaths
		log rasterFilePosixPaths
		-- you can then pass them to other handlers to process them
	end tell
	
end open

And here is the library script:

use scripting additions
use framework "Foundation"

property rasterTypeIDsList : {"public.png", "com.adobe.photoshop-image", "dyn.ah62d4rv4ge81a65c", "public.tiff"}
property vectorTypeIDsList : {"com.adobe.illustrator.ai-image", "com.adobe.encapsulated-postscript", "com.adobe.pdf"}

on collectFromItem:posixPath vectorFiles:vectorPaths rasterFiles:rasterPaths
	-- make an NSURL so we can get info
	set anNSURL to current application's class "NSURL"'s fileURLWithPath:posixPath
	-- things we want to know about the file
	set requiredKeys to {current application's NSURLIsDirectoryKey, current application's NSURLIsPackageKey, current application's NSURLTypeIdentifierKey}
	-- get the values as a dictionary
	set infoDict to anNSURL's resourceValuesForKeys:requiredKeys |error|:(missing value)
	-- check if it's a folder
	if (infoDict's objectForKey:(current application's NSURLIsDirectoryKey)) as boolean and (infoDict's objectForKey:(current application's NSURLIsPackageKey)) as boolean is false then
		-- get contents of folder
		set fileManager to current application's NSFileManager's defaultManager()
		set theFiles to fileManager's contentsOfDirectoryAtURL:anNSURL includingPropertiesForKeys:{} options:(current application's NSDirectoryEnumerationSkipsHiddenFiles) |error|:(missing value)
		-- loop through, passing files to this handler
		set fileCount to theFiles's |count|()
		repeat with i from 1 to fileCount
			set onePath to (theFiles's objectAtIndex:(i - 1))'s |path|()
			(my collectFromItem:onePath vectorFiles:vectorPaths rasterFiles:rasterPaths)
		end repeat
	else -- a file
		-- we only need to check the UTI
		set this_typeID to (infoDict's objectForKey:(current application's NSURLTypeIdentifierKey))
		-- workspace is used for UTIs
		set theWorkspace to current application's NSWorkspace's sharedWorkspace()
		repeat with aUTI in rasterTypeIDsList
			if (theWorkspace's |type|:this_typeID conformsToType:(aUTI as text)) as boolean then
				copy posixPath to end of rasterPaths
				exit repeat
			end if
		end repeat
		repeat with aUTI in vectorTypeIDsList
			if (theWorkspace's |type|:this_typeID conformsToType:(aUTI as text)) as boolean then
				copy posixPath to end of vectorPaths
				exit repeat
			end if
		end repeat
	end if
end collectFromItem:vectorFiles:rasterFiles:

Thanks, Shane

It is work fine :slight_smile: