Problem moving file names

Hi there,

I am new to the forums so hopefully I post in the correct place. I have been learning Applescript and I love it. I recently got stuck on a project. I am trying to create a script that takes a file, moves it, renames it and then opens it with a compressor droplet. I can get it to work without the rename and move but as soon as i do that compressor complains that there is a problem with the source file.

I am copying the code below. If anyone has ideas on what I did wrong, that would be wonderful.

Thanks!

:D:D:D:D:D:D



-- get the title of movie 
set movie_title to ""
display dialog "What is the title of your movie?" default answer movie_title
set movie_title to text returned of the result

-- set the title to lowerrcase and concatenate 
set lowercase_movie_title to movie_title's words as string
on trim(lowercase_movie_title_trimmed)
	--Make a list out of the text provided.
	set myText to words of myText
	
	--Change that list into a string of words that only have a single space between.
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to " "
	set myText to myText as string
	set AppleScript's text item delimiters to oldDelimiters
	
end trim
set lowercase_movie_title_trimmed to result


-- did they edit in HD or SD? 
set project_type to (choose from list {"HD", "SD"} with prompt "How was your movie made?") as string

-- grab the full quality file to compress 
tell application "Finder"
	activate
	set full_quality_file to (choose file with prompt "Select your full quality file") as string
end tell

-- move the full quality file to the final folder 
tell application "Finder"
	move file full_quality_file to folder "my folder address"
	set full_quality_file_a to result
end tell

tell application "Finder"
	activate
	set name of full_quality_file_a to (lowercase_movie_title_trimmed & ".mov")
	set new_full_quality_file to result
end tell

-- compress the hd or sd movie  
if project_type = "SD" then
	-- compress the SD Movie
	tell application "09cmf_H264_480pw" to (open new_full_quality_file)
else
	-- compress the HD Movie
	tell application "comp3_H264_720pw" to (open new_full_quality_file)
end if

Hi,

the problem is, you pass a file name (just a string) to the compressor, not the file itself.
Try this


.
set name of full_quality_file_a to (lowercase_movie_title_trimmed & ".mov")
set new_full_quality_file to full_quality_file_a as alias
end tell
.

Hey Stefan!

That worked, thank you so much. I had one other weird issue that I was having with the script. I was trying to rename the file with only alpha / numerics but it still comes back with $ and some other random symbols. Is there an easy way to rename a file name with only alphanumerics? The closest thing on the forum that I could find is this but it doesn’t remove all symbols.

http://macscripter.net/viewtopic.php?id=18519

Thanks,

Greg

AppleScript does exactly what you tell AppleScript to do :wink:
For example your trim handler on trim() is defined but will never be called in your script

Hey Stefan,

I am not sure what you mean in your answer. Right now it takes the name and pulls out spaces and also some symbols but seems to leave others (like $ always stays in for some reason). not sure what I am missing…

Also, my last piece of this script is I am trying to figure out how to let the user choose from a list of schools and then based on their choice pass a corresponding school initial to the next action. Any thoughts on the best way to do that?

Thanks again - this site has been awesome!

Greg

the subroutine on trim() does actually nothing, because a subroutine placed within the implicit run handler of a script will be just skipped.
It must be called with a line like this


set lowercase_movie_title to trim(movie_title's words)

in your script the space characters (and some other characters) will be removed with

set lowercase_movie_title to movie_title's words as string

but this works only, if the text item delimiters are set to an empty string.

The reason for the irregular behavior is, the keyword words treats some special characters as a word delimiter.
You can lowercase all characters and remove everything but alphanumeric characters with


set theText to "ThiS/ª©is A Å“@∆πøte st"
do shell script "/bin/echo " & quoted form of theText & " | /usr/bin/tr A-Z a-z | /usr/bin/tr -cd [:alnum:]"
--> "thisisatest"