Help with Syntax

I’m pretty new to AppleScript and I think I’m having some trouble getting the syntax right, and understanding dictionaries. My goal is to create a droplet where I can drop audio files onto. The droplet should create a new folder with a similar name to the audio file, and then create new audio files sliced at each marker in the audio file, which end up in the new folder. I’ve found an audio application, Sound Studio, which appears to be both AppleScriptable, and have a function to Slice on Markers. I’m having trouble getting the AppleScript to work with it though, and was hoping someone could help. Here’s the code I’m trying:

on open names
	repeat with aFile in names
		set myInfo to info for aFile -- get the file info
		set myName to displayed name of myInfo -- get the file's name
		set myOffset to offset of myName in aFile as text -- get where the file name starts
		set myParentFolder to (characters 1 thru (myOffset - 1) of (aFile as text)) -- get the parent folder's path
		
		-- make a folder to contain the slices
		tell application "Finder" -- have the finder make a folder for this files slices
			set sliceFolder to make new folder at ((myParentFolder as string) as alias) with properties {name:myName & "_slices"}
		end tell

		--set sliceFile to sliceFolder as file
		set fileString to (sliceFolder as string)
		set newFileString to fileString & "slice.aiff"
		set newFileRef to newFileString as file specification
		set sliceFileSpec to fileString as file specification
		set fileRef to aFile as reference
		
		-- have Sound Studio split the file on it's markers
		tell application "Sound Studio"
			open fileRef  -- open the file
			delay 1 -- wait for the file to open
			split by markers into sliceFolder  -- split the file
		end tell
		
	end repeat
	
	-- Remove the following line if you want the application to stay open.
	quit
end open

I can create the folder, and open the audio file if I comment out the split line. If I leave that in I’m not able to compile, but get this error:

Here is the dictionary entries for Sound Studio that I used (If there are more that you need to see let me know):
Open:

Split:

Any help would be great. Thanks

Nathan

Hi,

I can’t test right now, but I think you can fix your problem with the following change. Not that it’s really “your problem”…I mean, that sounds bad…let’s say it’s your code’s problem. :slight_smile: :

  -- make a folder to contain the slices 
      tell application "Finder" -- have the finder make a folder for this files slices 
         set sliceFolder to make new folder at ((myParentFolder as string) as alias) with properties {name:myName & "_slices"} as file specification -- maybe and/or 'as alias'
      end tell 

Also, you should be able to take out that ‘delay’ statement. Normally, AS waits until a command is finished before moving on to the next one. It would be unusual for ‘Sound Studio’ to behave differently–I think its developer(s) would have had to go out of their way.

Very thorough job of describing the issue you encountered, by the way. Let us know how it goes.

Thanks for the reply. I tried both as alias, and as file specification, and both gave me the error, can’t make folder into a alias (or file specification).

After creating the folder, I change it to a string, and then to a file specification, but using that reference didn’t change how it worked either.

Do I have the syntax for the slice command correct? I’m not sure if I’m reading the dictionary correctly or not, but when I try “slice by markers” it won’t compile. Is there something I’m leaving out? Thanks

Nathan

Hi Nathan,

you have to specify the document right after the split command.

split fileRef by markers into sliceFolder

I don’t know whether you must open the file but you have to target the split command at the file, you want to split.

Have a look at the dictionary again:

The first line says: split document – the target document

Now, when I’m reading this again, I think you’ll have to open the file.
Otherways the dictionary would tell you: split reference - the target document.

So try:

split document 1 by marker null into splitFolder

or try:

split front document …

I don’t have Sound Studio, so I can’t test it.

Welp, I’m still not at a Mac, but perhaps you need some parentheses. Without them, I suppose ‘make’ might think ‘as’ is a parameter it doesn’t understand.

tell application "Finder"
         set sliceFolder to (make new folder at ((myParentFolder as string) as alias) with properties {name:myName & "_slices"}) as alias 
      end tell


Finder can coerce object specifiers to alias, so something along these lines has to work. Along with Peter's suggestions, you should be good to go.

OK, now I’m at a Mac. The following script should work. The Finder part is tested. If referencing the front document doesn’t work properly, you can also try ‘document 1’ or ‘document -1’. The ‘open’ command is so you can test it in your script editor.

open {choose file}

on open eachFile
	repeat with thisFile in eachFile
		tell application "Finder"
			set {thisName, parentFolder} to {name, container} of thisFile
			set sliceFolder to get (make new folder at parentFolder with properties {name:thisName & "_slices"}) as alias
		end tell
                   tell application "Sound Studio" 
                    open thisFile
                    split front document by markers into sliceFolder
              end tell 
	end repeat
	quit
end open

Oh, you don’t need that ‘quit’ command either. Unless you specify otherwise when saving, a droplet will automatically quit when it’s done.

Peter:
For the split I tried:

split document 1 by markers null into sliceFolder

which gets changed to:

split document 1 marker null into sliceFolder

when I save. Then when I try to compile it this way I get the error:

Expected end of line, etc. but found class name. (-2741)

I’m not sure if this is getting changed to something it shouldn’t, or if I’m not setting something correctly.

Michael:
Adding the parentheses worked for both alias and file specification. I’m still having problems with the split command, though.

Thank you both for your help, I really appreciate it. If you have any more suggestions, that would be great.

Mark:
I think I overlooked your second response after youd made it back to a computer. This seems to work, except for the split command. When I try to save it with the line:

split front document by markers into sliceFolder

I get an error: Expected expression but found paramater name. and “into” is highlighted. If I comment out the line starting after “document” it seems to run fine.

On another note, I was wondering where you found how to do the first line of the “tell the Finder” section. I think I understand what it does, and I think I was doing something similar before, but it looks like I was taking the long way around. That may be somethign that’s better saved for another topic, though, so this doesn’t get split off in another direction.

Nathan

Regarding the ‘split’ line: I guess you can try:

split front document by markers null into sliceFolder

That would be pretty silly, but maybe the developer didn’t know the right way to do it so just used ‘null’ as a constant. Or does the dictionary suggest anywhere what sorts of values ‘by markers’ will accept?

Regarding the Finder command: Yes, that’s essentially what you were doing, I just shortened it.

  tell application "Finder" 
     set {thisName, parentFolder} to {name, container} of thisFile 
     set sliceFolder to get (make new folder at parentFolder with properties {name:thisName & "_slices"}) as alias 
  end tell 

The first command uses mutliple assignment to set ‘thisName’ to ‘name’ and ‘parentFolder’ to ‘container’. You can put application references like ‘name’ and ‘container’ in a list like that where some combination of ‘ofs’ and ‘tells’ outside the list specifies a path through the application’s object containment hierarchy. Basically, it just takes practice to recognize when and how you can word it. ‘container’ is a property of Finder’s ‘item’ scriptable class that many other Finder objects inherit from, like ‘file’ and ‘folder’. You can use it to easily get a reference to a file system object’s parent. Simpler than parsing the path string.

When I try:

split front document by markers null into sliceFolder

it gets changed to:

split front document marker null into sliceFolder

and I get the error message:

Expected end of line, etc. but found class name

and “marker” is highlighted.

I don’t think the dictionary says anything about by markers, and what it will accept, but I don’t think I’m very good at reading the dictionaries yet. If you want, and it would help, you can get a demo of Sound Studio at http://www.felttip.com/products/soundstudio/download.shtml. This gives you a 14 day demo, and it’s what I’m working with. As far as I know, it’s a fully functional demo but quits working after 14 days of use.

Nathan