Tearing my hair out - create alias to import to iTunes

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Ok, what I'm trying to do is this:

1) Monitor the Movies and TV Shows folder on my external HD.
2a) If an mkv is added, run iFlicks and remux it as iTunes Compatible then delete original file
2b) If an avi is added, run iFlicks and convert it to Apple TV/iPad format then delete original file
3) Create an alias to the newly created m4v file and place it in my "Automatically Add to iTunes" folder
4) Delete the alias from said folder

Step 3 has to be done like this because I don't want to copy the movie/TV show to my iTunes Media folder when importing. Otherwise I would just use iFlicks Import command. The only way I know of to programmatically import a file to iTunes whilst leaving the source file in place is to place an alias in the Automatically Add to iTunes folder.*

1, 2 and 3 I have managed myself but what happens is the same file gets imported into iTunes many times. I need a way of deleting the alias from the AAtI folder after it's been imported.

*I'm aware there's an option in iTunes to turn of Copy to iTunes Media folder, but I don't want to turn this off, because my books and music etc DO reside in my iTunes Media folder and I like iTunes copying them there automatically.

Many many thanks
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

I'm not sure how iTunes will deal with it in this case. If you give it an alias, it might import the alias and therefore deleting the alias may break it in iTunes. That said, is there a reason why you can't add a "Move to trash" action after the "Make alias" one?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

That would add the file being processed to the trash, surely? Not the alias?

Deleting the alias doesn't cause the link in iTunes to break, I've deleted them manually after import and everything still works.
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Any actions after a "Make alias" action operate on the alias so you should be fine there. In general, if the action produces a new file (copy, archive, unarchive, make alias, etc.), the subsequent actions operate on that new file.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Great, I'll try that. I just wonder how long iTunes takes to add files placed in that folder? Maybe I might need to insert a pause or delay before the delete?
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Ok, on first test that seemed to work! The alias was placed in the folder, the file was added to iTunes, then the alias was moved to the Trash!

Is there any way to bypass the Trash and delete the file completely?
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Arrrgghh, back to square one! My embedded script of:

Code: Select all
if extension of theFile is in {"avi", "wmv"} then
   tell application "iFlicks"
      import theFile as new Apple TV & iPad video with deleting without gui
   end tell
else if extension of theFile is in {"mkv", "mp4"} then
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
end if


now gives the following error in the console log:


2013-08-13 21:17:26.275 hazelworker[30302] filename.mkv: Rule Apple TV matched.
2013-08-13 21:17:26.343 hazelworker[30302] [Error] AppleScript failed: Error executing AppleScript on file /Volumes/MediaCentre/TV Shows/name/filename.mkv.
2013-08-13 21:17:26.346 hazelworker[30302] AppleScript error: {
NSLocalizedDescription = "Can\U2019t get extension of alias \"MediaCentre:TV Shows:name:filename.mkv\".";
NSLocalizedFailureReason = "Can\U2019t get extension of alias \"MediaCentre:TV Shows:name:filename.mkv\".";
OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: null()>";
OSAScriptErrorBriefMessageKey = "Can\U2019t get extension of alias \"MediaCentre:TV Shows:name:filename.mkv\".";
OSAScriptErrorMessageKey = "Can\U2019t get extension of alias \"MediaCentre:TV Shows:name:filename.mkv\".";
OSAScriptErrorNumberKey = "-1728";
OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'obj '{ 'form':'usrp', 'want':'prop', 'seld':'utxt'(\"extension\"), 'from':'obj '{ 'want':'alis', 'from':null(), 'form':'name', 'seld':'utxt'(\"MediaCentre:TV Shows:name:filename.mkv\") } }>";
OSAScriptErrorRangeKey = "NSRange: {0, 0}";
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Ok, I simplified a bit just to get it working - I set Hazel to process file with extension "mkv" and if found, run the embedded script:

Code: Select all
tell application "iFlicks"
   import theFile as QuickTime movie with deleting without gui
end tell


then Make Alias in Auto Add to iTunes folder, then delete alias.

But I've spotted a flaw - the Make Alias obviously runs on the mkv file. But I want it to run on the m4v file that's the output of the AppleScript!
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Read the in-app help on AppleScript. Hazel can't know what your script produces so you need to return a record entry which tells it to target a different file.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Ok, I've set Hazel to run an external AppleScript when a file of Kind "Movie" is added to the folder.

The script is:

Code: Select all
on hazelProcessFile(theFile)
   if extension of theFile is in {"avi", "wmv"} then
      tell application "iFlicks"
         import theFile as new Apple TV & iPad video with deleting without gui
      end tell
   else if extension of theFile is in {"mkv", "mp4"} then
      tell application "iFlicks"
         import theFile as QuickTime movie with deleting without gui
      end tell
   end if
end hazelProcessFile

return {hazelSwitchFile}


But still throws up a "Can't get extension of alias" error.

I think I'm gonna give up :cry:
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

You need to send a record (google for AppleScript records). You basically have to specify what the actual file is.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sorry, I don't understand. I've Googled, I've borrowed an AppleScript book, I just can't get my script to run, it ALWAYS generates a "Can't get name of alias" error.
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Look at the last section here:

http://en.wikibooks.org/wiki/AppleScrip ... nd_records

Notice how you need both a name and a value, separated by a colon.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sorry, I don't understand.
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Look at the record in that example. Yours looks like this:

{ hazelSwitchFile }

The ones there look like this:

{ hazelSwitchFile : something }

You are just listing a property name there without any value. You are leaving the value blank so Hazel has no idea what file you are talking about. You need to specify an alias to the new file after the colon.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Support