batch export and filename

I am modifying a quicktime batch export script that was posted here previously. I would like to export the source filename.MOV as filename.MP4, which is working fine - sorta. What I am struggling with is the filename of the resulting file. It comes out as filename.MOV.MP4. I know there must be a simple method of providing just the filename (left of the dot) and then the extension. In my code below, thisFile always includes the extension. What method should I be using to utilize the the left of the dot name?

export to (exportFolder & thisFile & ".mp4") as QuickTime movie using settings "Macintosh HD:USERS:KARMS:Desktop:streaming:hinted_hi-res.set"

This is one way, it will leave everything left of the dot - if the extension is three characters.


set thisFile to choose file
set fileName to characters 1 through -5 of name of (info for thisFile) as string

You can change your line to this:

export to (exportFolder & (characters 1 through -5 of name of (info for thisFile) as string) & ".mp4") as QuickTime movie using settings "Macintosh HD:USERS:KARMS:Desktop:streaming:hinted_hi-res.set"

It would be better to use text instead of characters:

choose file without invisibles
set thisName to text 1 thru -5 of name of (info for result)

If you don’t know how long the extension is, then you can use text item delimiters:

choose file without invisibles
set thisName to name of (info for result)

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"."}
try
	-- Use a try block in case the file doesn't have an extension
	set thisName to text 1 thru text item -2 of thisName
end try
set AppleScript's text item delimiters to ASTID

Oh heck, that’s what started to post, then I changed it because I mixed up which was the better way. :rolleyes:

Thanks for the reminder.

Thanks for the responses. Since this is a batch process, isn’t the use of Choose going to interrupt the batch asking for a filename? I probably didn’t clarify it - sorry. Bellow is the repeat I’m trying to incorporate this “filename” issue into… I tried inserting the “set thisName”, but the result is that the filename isn’t found.

repeat with thisItem in droppedItems
	if (folder of (info for thisItem without size)) is true then
		list folder thisItem without invisibles
		
		repeat with thisFile in (result)
			set thisName to text 1 through -5 of name of (info for result)
			tell application "QuickTime Player"
				open ((thisItem as Unicode text) & thisFile)
				if (can export (front movie) as MPEG4) is true then
					tell first movie
						try
							export to (exportFolder & thisName & ".mp4") as QuickTime movie using settings "Macintosh HD:USERS:KARMS:Desktop:streaming:hinted_hi-res.set"
						on error errorMsg number errorNum
							display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "OK" default button 1 with icon caution
						end try
					end tell
				else
					display dialog "QuickTime Player can't export "" & (thisFile as Unicode text) & "" as MP4." buttons "OK" default button 1 with icon caution
				end if
				close front movie
			end tell
		end repeat
		
		try
			tell application "Finder" to delete thisItem
		on error errorMsg number errorNum
			display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "OK" default button 1 with icon caution
		end try
	end if
end repeat

People often use this as an easy way to demonstrate something; it doesn’t mean you have to use it in your script.

Change this.

 set thisName to text 1 through -5 of name of (info for result)

.to this:

 set thisName to text 1 through -5 of name of (info for thisFile)

Thanks Bruce - I kinda figured that, but didn’t know for sure. Either way I get the same result with both ways. Below is the event log of the error, which is the same for both ways also…

tell current application
choose folder with prompt “Change video files from these folders:” with multiple selections allowed
{alias “Macintosh HD:Users:karms:Documents:batch input:”}
end tell
tell application “QuickTime Player”
activate
close every window
end tell
tell current application
info for alias “Macintosh HD:Users:karms:Documents:batch input:” without size
{name:“batch input”, creation date:date “Friday, September 1, 2006 7:18:08 AM”, modification date:date “Friday, September 1, 2006 11:06:57 AM”, icon position:{0, 0}, size:missing value, folder:true, alias:false, package folder:false, visible:true, extension hidden:false, name extension:missing value, displayed name:“batch input”, default application:alias “Macintosh HD:System:Library:CoreServices:Finder.app:”, kind:“Folder”, folder window:{0, 0, 0, 0}, file type:"

Weird - the event log is truncated in my previous post… here is the part that shows the error.

list folder alias “Macintosh HD:Users:karms:Documents:batch input:” without invisibles
{“diversion.mov”}
info for “diversion.mov”
“File diversion.mov wasn’t found.”

Oh, that’s right, you’re using list folder; That returns a list of just names, so you don’t need to ask for it. Use this instead:

set thisName to text 1 through -5 of thisFile

That did it - :smiley: Thaks for the help. This will save me lots of time.