I'm trying to write a new script, but I'm confused

I don’t know if any of you are familiar with the program MacTheRipper, but I use it fairly often to burn my brothers DVD’s.

This is what I’m trying to do:

Whenever I put a DVD in, I want a new folder called DVD_MOVIE to be created on the desktop. Then, I want MacTheRipper to open, and start ripping to DVD into this folder.

So far, I have gotten so when the DVD is inserted, the new folder is made and named, and MactheRipper opens.

I think the next thing I have to do is tell my computer to pause for 20 seconds while MacTheRipper scans the DVD, and then I have to actually start ripping the DVD. I think the easiest way to do this would be to keystroke return or enter, since the go button in MacTheRipper is highlighted, but I’m not sure how to go about doing this.

This is my current script:

tell application "Finder"
	activate
	make new folder at folder "Desktop" of folder ¬
		"JHaswell" of folder "Users" of startup disk ¬
		with properties {name:"DVD_MOVIE"}
end tell
tell application "MacTheRipper"
	activate
end tell

I have that script set to run every time a DVD is inserted.

So if anyone could help me out, that would be great. Plus, as I’m slightly naive in this branch, if someone wanted to explain how it works, I’d love to try and learn. If not, any help would be appreciated. Thanks in advance

Model: eMac
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Something like this (not tested)


tell application "Finder"
	activate
	make new folder at folder "Desktop" of folder ¬
		"JHaswell" of folder "Users" of startup disk ¬
		with properties {name:"DVD_MOVIE"}
end tell
tell application "MacTheRipper"
	activate
	delay -- (experimentally determined bunch of seconds)
	tell application "System Events" to tell process "MacTheRipper" to keystroke return
end tell

great, that worked well. System events is just the program needed to preform keystrokes?

Now, another question: After return is keystroked, a window pops up to select a destination to rip the DVD to. I want to pick the folder DVD_MOVIE. The one that was created when the DVD was inserted.

I know it will have something to do with selecting the folder of DVD_MOVIE at folder “desktop” of folder “JHaswell” of folder “users” of startup disk, but I don’t know how to word it. Is there a way to do this?

Can I keystroke it again? It would be easier I think to just select that folder, but if that isn’t an applescript command, I can get to the folder by pressing the up arrow button 8 times and the right arrow button once. Do I need to keystroke this all again?

Thanks

Hi I have incorporated the other part of the script I wrote for you over on Macosxhints
(note: the change in how it gets the dvd, my tests on this have worked ok so far)

I assume you want MactheRipper to rip the dvd into the New folder.
So thats the new part of the script, it writes the new folder name to MactheRipper’s preferance.
**edit I just seen you next post here, and on macosxhints.
For some reason anything after the ( «constant **** ) will not display on on macosxhints. or here,

here is a link to it in html

http://uk.geocities.com/markosx@btinternet.com/osxhintsimages/DVDScript.html

Doesn’t show on your site, either. Do you know if there are any null bytes (ASCII character 0) in your code?

??

it seems to be the (*) for some reason they are not normal.

To get the part between the (« ») inserted a dvd and run

tell application "System Events"
	set DVD_Name to (format of disks whose ejectable is true)
end tell

maybe someone know how to convert it??

Mark, there are two null bytes after the asteriks:

tell application "System Events"
	set DVD_Name to (format of disks whose ejectable is true)
end tell

character 15 of ("" & item 1 of result)
ASCII number result
--> 0

Thanks Bruce, Err… do you know how I fix it??

this is what I got from the link:

tell application “MacTheRipper”
quit
end tell
tell application “System Events”
set DVD_Name to (name of disks whose ejectable is true and format is «constant ****

I’m confused again. Why is MacTheRipper quitting? and what is «constant ****?

By the way- After reading the conversation you two just had, I feel like a complete moron. I was so happy after discovering applescript, and then you two go and have a conversation that might as well have been in greek for all I understood:P

I feel the same. :wink:

There is a problem with the content of the script so it is not showing up on these webpages, what you are getting is incomplete.

The script below will create the correct script that I am trying to show you (I hope)

BEFORE YOU RUN THIS MAKE SURE YOU HAVE A DVD IN YOUR DISK DRIVE.
MAKE SURE THAT NO OTHER TYPE OF DISK IS MOUNTED i.e… (CD’s , DMG)
MAKE SURE YOU ONLY HAVE ONE DVD MOUNTED.

-- BEFORE YOU RUN THIS MAKE SURE YOU HAVE A DVD IN YOUR DISK DRIVE.
--MAKE SURE THAT NO OTHER TYPE OF DISK IS MOUNTED i.e. (CD's , DMG)
-- MAKE SURE YOU ONLY HAVE ONE DVD MOUNTED.
on run
	tell application "System Events"
		set Sc_constant to "tell application \"System Events\"
	set the_constant to " & (format of disks whose ejectable is true)
	end tell
	tell application "Script Editor"
		set the_name to name of document 1
		set the_contents to contents of document the_name
		set AppleScript's text item delimiters to "Script_Start_Point"
		set the_content to text item -1 of the_contents -- this works from bottom of text to first break point  "Script_Start_Point"
		set AppleScript's text item delimiters to "Script_End_Point"
		set script_text to text item 1 of the_content
		set AppleScript's text item delimiters to ""
	end tell
	
	set script_text to Sc_constant & script_text
	set file_path to (path to desktop as Unicode text) & "DVD_RIPPER.scpt"
	
	tell application "Script Editor"
		make document with properties {text:script_text}
		save document 1 as "Script" in file file_path
		compile document 1
	end tell
	
end run

(*

 Script_Start_Point

	set DVD_Name to (name of disks whose ejectable is true and format is the_constant)
end tell
if DVD_Name is not {} then
			repeat with i from 1 to number of items in DVD_Name
				set this_dvd to item i of DVD_Name
				tell application "Finder"
					tell application "System Events"
						set DeskTopFolder to path of desktop folder
					end tell
					if not (exists folder this_dvd of alias DeskTopFolder) then
						set the folder_maker to make new folder at alias DeskTopFolder with properties {name:this_dvd}
						reveal folder_maker
						
						set plistPath to "com.Geezerbuttz.mtr"
						set PosiPath to POSIX path of (DeskTopFolder & this_dvd as string)
						
						do shell script "defaults write " & plistPath & "  OutPath " & PosiPath
						delay 1
						
						tell application "MacTheRipper"
							activate
							
							delay 5 -- (experimentally determined bunch of seconds)
							tell application "System Events" to tell process "MacTheRipper" to keystroke return
						end tell
					end if
				end tell
			end repeat
		end if

Script_End_point <--- **** this is the Script end  point *** 
*)

I’m having conflicting emotions. That script confuses me so much, which makes me sad. But it works!!! :slight_smile: :wink:

It made a folder for my Eurotrip DVD with the same name, opened MacTheRipper, MacTheRipper scanned the DVD, and then the keystroke return told MacTheRipper to start scanning. Now I just have to figure out how to tell MacTheRipper to select the new folder.

What was that whole script? Was that a script…to write another script? Because that’s what it did. It made a new script entitled DVD_RIPPER. Do I have to make sure all other CD’s and everything are ejected everytime? Or was that just for the script of the script thing?

Yes that is what it should have done. (hopefully you get the part in it with the all the «constant thing

No that was just to get the correct type.

Now the first script I wrote over on Macosxhints is not really needed. Nor is most of this if your aim was to
just have MactheRipper save to a folder named after the inserted DVD.

I may misunderstand your objectives and I am not complaining because I have had fun believe it or not trying to figure things out.
But next time it may save time if you explain your whole goal first.

Now open up MactheRipper go to its Preferences and untick the ‘Dont remember Save Location’
OK that, and then go to the File menu and set you location to your desktop.

the script you shoud use is :


tell application "MacTheRipper"
                           activate
                           
                           delay 5 -- (experimentally determined bunch of seconds)
                           tell application "System Events" to tell process "MacTheRipper" to keystroke return
                       end tell

MactheRipper should now Create the folder it’s self on you desktop and write to it

oh my god. I’m so sorry. It never occurred to me that it would be that easy. I just figured that I would go in natural steps. I just wasted a lot of your time.

Thank you so much, and I’m sorry about all that. Next time I’m fooling around with scripts and need help, maybe I’ll just post my entire problem

erm- what’s the applescript wording to tell an application to hide?

Don’t feel too bad, Ttws. There are numerous instances where a specific question is asked about a method “ when, once the general objective is clarified, the answer can turn out to be quite different…

Anyway, good to see that you have a solution. :slight_smile:

As to the question of hiding an application (actually, an application process), this can normally be achieved by using System Events:


tell application "System Events"
	set visible of application process "Safari" to false
end tell


Some of these constants use characters from the low end of the ASCII range “ which, in certain situations, may be interpreted as control characters (codes originally intended to control devices, such as printers, instead of carrying printable information). The null character (ASCII character 0), sometimes used to terminate a character string literal, can cause particular problems “ as you’ve discovered. It doesn’t help that most of these characters are not visible, either.

While a number of the disk format constants are represented by recognisable terms (such as Apple Photo format, AppleShare format, audio format, High Sierra format, ISO 9660 format, Mac OS Extended format, Mac OS format, NFS format, ProDOS format, QuickTake format, UDF format, UFS format, unknown format, and WebDAV format), these will normally need to be wrapped in a System Events or Finder tell block to compile. Other formats, for which a term has not been defined, may need to be specified using the raw constant codes. This is where display irregularities could creep in.

One way to work around this (when necessary) might be to start with a text representation of the code, and then coerce that to a constant.

To demonstrate:


on text_constant(c)
	set l to ({{c:c}} as text)'s items -4 thru -1
	repeat with i in l
		set i's contents to ASCII number i
	end repeat
	set text item delimiters to ") & (ASCII character "
	set l to "(ASCII character " & l & ") as constant"
	set text item delimiters to {""}
	l
end text_constant

tell application "System Events" to set l to name of disks
set d to choose from list l with prompt "Choose a disk:"
if d is false then error number -128
tell application "System Events" to set t to my text_constant(format of disk (d's beginning))
tell application "Script Editor" to execute (make document with properties {contents:t})


Thanks Kai,

hopefully I will not run into that too often