Applescript and Visualhub

Hello,
Sorry if this has been asked before but i went through the forums and couldn’t find a relevant answer. I’m looking for a script which will monitor a a folder for any files every minute once any file is detected it will perform the following.

  1. Run visualhub and load a preconfigured settings file.
  2. Convert the file.
  3. After the conversion move the original file to folder X and the new converted file to folder Y. The new converted file has to be moved after the conversion is complete rather then be created in folder Y.

Visualhub has been discontinued and their sourceforge forums are inactive so i didn’t know where else to ask for help. I’m really new to applescripting and would appreciate any help or being pointed in the right direction.

Many thanks.

Model: Macmini
Browser: Safari 534.30
Operating System: Mac OS X (10.5)

I can make it detect when somethings in there, but i dont know what visualhub is…

EDIT: Ok, I just downloaded it, its a video converter, I’ll try and work on what you wanted it to do :slight_smile:

Ok, I cant get my VisualHub to work cause you need to download a file upon installation thats no longer available on their servers, but heres my guess at the code: (tell me where you get an error)

tell app "VisualHub"
read from file path name ((path to desktop as string) & "FolderX") as alias
write to file‚path name (((path to desktop as string) & "FolderY") as alias) of type .AVI -- maybe just avi, no dot?
end tell

Sorry, wish I could help more

Many thanks for the help and quick reply! I’ve tried all sorts of scripts but making the app itself write the file is a bit confusing. If it helps i could upload the program itself ?

Try looking through the app’s dictionary, thats where are the commands are stored, i just took a look and this app has a ton, whatever you want, its bound to be in there. And yup, anytime :slight_smile:
(File → Open Dictionary… → VisualHub)

That’s the issue I’m facing, i found the massive list of commands which has every single command to convert videos into different types but I can’t seem to figure out how to execute commands after the conversion is complete, if it helps then the program opens a dialogue window with the text ‘conversion complete’ and options OK and Show Details. If there could be a way to detect that dialogue window to execute the next command ?

Maybe convert something, then leave the Complete window up and go to a new AS window and write code for ur app to activate, then check the frontmost window (cant remember code for that, look it up) so it’ll be tell app “BLAH” activate code for front window end tell. Then copy and paste the id it gives you and check for that in ur code? That might work

Thanks, i’ll give it a shot.

Ok, tell me how it works

Hey i managed to do what i was looking here for but I’ve run into another problem. Here’s my complete applescript so far.
This script will perform the following actions.

  1. Open an intro file from a static location copy all its content.
  2. Open a file called xyz.mp4 from a static folder and paste copy from first document and save it as xyz.mov
  3. Move the xyz.mov to another static location.
  4. Then another software VisualHub uses xyz.mov to convert it into xyz.flv .

Problem:

In this example everything was done on a file called xyz , this file name will be different everytime. I could just tell quicktime to pick mp4 files but when saving i will need to write the same file name in mov. There will always only be one file in the first folder ‘mp4files’. So what I’m looking for is a script that will retrieve the filenames of the folder ‘mp4files’ without the extension so when saving the quicktime file i could use that filename that was retrived earlier and just add .mov at the end.

Also if possible i’d also like to know how would i go about saving a file in quicktime by giving a destination folder then the file name which was retrived in first example then add a .mov extension to it.

If the script sounds confusing then basically all this script is being executed on a file called ‘xyz’ , i want it so that if any file lands in mp4files folder it could be executed on it.


tell application "QuickTime Player"
	open "/Users/pkp/Desktop/factory/intro.mov"
	tell document 1
		select all
		copy
		close window 1
	end tell
end tell
tell application "QuickTime Player"
	open "/Users/pkp/Desktop/factory/xyz.mp4"
	paste document 1
	tell document 1
		save self contained in "/Users/pkp/Desktop/factory/xyz.mov"
	end tell
	close window 1
end tell

set sfile to "xyz.mov"
set sfolder to "Macintosh HD:Users:pkp:Desktop:factory:movfiles:"
set sfilepath to (sfolder & sfile) as text

set dfolderpath to "Macintosh HD:Users:pkp:Desktop:movfiles:"

tell application "Finder"
	move (sfilepath as alias) to (dfolderpath as alias)
end tell

set cfile to ({"Macintosh HD:Users:pkp:Desktop:movfiles:xyz.mov"})

tell application "VisualHub" to set VisualHub to load script (scripts path of main bundle & "/automation.scpt" as POSIX file)

tell VisualHub
	AddFiles(cfile)
	LoadSettings("/Users/pkp/Documents/settings1.vhub")
	StartConversion()
	QuitApp()
end tell

Model: Macmini
Browser: Safari 534.30
Operating System: Mac OS X (10.5)

So the xyz.mov file is the intro followed by the xyz.mp4 compiled into 1 thing?

nope a file called ‘xyz.mp4’ is put into a folder ‘mp4files’ then Quicktime adds a intro to it and saves it as .mov with the same first name and moves it to another folder called ‘movfiles’ . Then visualhub turns the mov file into an flv file with the same name. Want i want is a way in which no matter what ‘xyz.mp4’ is called, it will perform the same actions.

Basically a variable , something like ‘set mp4file to (first file of folder mp4files)’ but it has to be without extension so when quicktime is saving it as mov, i can give it the same name and add mov to it. So xyz needs to be a variable rather then a static value.

So any file put into the mp4files folder should go through that process?

Yes

Have you used folder actions setup before? You right click on the folder and add folder action. Then you start you could with:

on adding folder items to this_folder after receiving theDetectedItems

and end with:

end adding folder items to

then whenever you add a file in it will run that script. I think this is what you want, if not tell me what you do want :slight_smile:
PS: theDetectedItems is the aliases of all the files added (in a list), you can use whatever variable you want it to store them to there, like:

on adding folder items to this_folder after receiving listOfAliases

Or whatever you want

I have setup folder actions but the problem is telling quicktime what filename to save the file with. So if its xyz.mp4 it has to save with xyz.mov , any idea how would one go about doing that ?

I was thinking maybe it could get filename without extension in the first folder then give set a variable which can take the filename and add .mov to it and give it to quicktime to save the file. I’ve managed to extract the filename without extension, for example if

set filename to xyz

how can i add an extension to this, like

set filename to filename & “.mov”

either this or any other method would do. Sorry if i sound too confusing.

Yeah, try finding the offset of “.” inside the POSIX Pathname and getting the txt between that and the last “:” and use that
Try this code:

set theItems to number of items in theDetectedItems
set ItemNames to {}
repeat with i from 1 to theItems
	set thePath to ((item i of theDetectedItems) as string)
	set thePathCopy to thePath
	repeat
		if (offset of "." in thePathCopy) is 0 then exit repeat
		set thePathCopy to text ((offset of "." in thePathCopy) + 1) thru end of thePathCopy
	end repeat
	set theDot to (length of (thePathCopy)) + 1
	repeat
		if (offset of ":" in thePath) is 0 then exit repeat
		set thePath to text ((offset of ":" in thePath) + 1) thru end of thePath
	end repeat
	set ItemNames to ItemNames & {(text 1 thru ((length of thePath) - theDot) of thePath)}
end repeat

itemNames will be a list with all of the names of the files you put in (ie {"User:desktop:somefolder:five.txt, “User:desktop:somefolder:song.mp4”, “User:desktop:somefolder:pic.jpeg”} returns {“five”, “song”, “pic”} ) so you can then take that and append a “.mov” to each one
Tell me if it doesnt work! :smiley: