Tearing my hair out - create alias to import to iTunes

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

Moderator: Mr_Noodle

For example, see posts using hazelSwitchFile:posix_parent_dir in forum search results for hazelSwitchFile.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

I've changed the script to the following, and whilst it works fine to capture the file and import it to iFlicks for converting, I'm struggling to create an alias of the resulting m4v file and place it in the Automatically Add to iTunes folder:

Code: Select all
if name extension of (info for theFile) is "mp4" then
   -- display dialog "Passing Through import - mp4" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "mkv" then
   -- display dialog "Passing Through import - mkv" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
      set newFile to POSIX path of the result
   end tell
else if name extension of (info for theFile) is "m2ts" then
   -- display dialog "Passing Through import - m2ts" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "avi" then
   -- display dialog "Converting import - avi" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as new Apple TV & iPad video with deleting without gui
   end tell
end if

{hazelSwitchFile:newFile}

tell application "Finder"
   move theFile to "/Users/<me>/Music/iTunes/iTunes Media/Automatically Add to iTunes/" as alias
end tell
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

You need to return that record at the end. I'm not sure if having it appearing in the middle will work.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Hazel doesn't seem to recognise Applescripts "result" keyword - it tells me there is no variable defined called "result"
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

I moved it to the end and it still tells me the variable "result" is undefined.
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

That has to do with your use of "result" earlier in the script.

Also, the last line should be something like:
Code: Select all
return {hazelSwitchFile:newFile}
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

The following script STILL tells me the variable "result" is undefined:

Code: Select all
if name extension of (info for theFile) is "mp4" then
   -- display dialog "Passing Through import - mp4" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "mkv" then
   -- display dialog "Passing Through import - mkv" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "m2ts" then
   -- display dialog "Passing Through import - m2ts" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "avi" then
   -- display dialog "Converting import - avi" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as new Apple TV & iPad video with deleting without gui
   end tell
end if

return {hazelSwitchFile:the result}

tell application "Finder"
   move theFile to "/Users/<me>/Music/iTunes/iTunes Media/Automatically Add to iTunes/" as alias
end tell
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

MoodyM wrote:The following script STILL tells me the variable "result" is undefined:

Because it is undefined in that version of your script.

You removed the newFile variable, which Mr_Noodle had suggested using.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

I tried it with "result", I tried it with "newFile" I tried setting "newFile" to "the result", all ended up with "variable undefined errors".

In English, what I want to do is take an mkv, m2ts, avi for wmv file, and use if statements to use iFlicks to convert/remux it to an m4v.

I then want to capture that m4v, create an alias to it, and place the alias in my Automatically Add to iTunes Folder.

Sounds simple. I feel really, really stupid. :oops:
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

It appears you keep using a variable that is undefined. I suggest trying your script outside of Hazel and getting it working there before you use it in Hazel. As far as I can tell, this error has nothing to do with Hazel and more to do with the script itself.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I'd happily just use OS X's Folder Actions to do the whole thing, but it has 2 problems:

1) I always find Folder Actions unreliable - sometimes the Folder Actions triggers, sometimes it doesn't.

2) I’d have to create a Folder Action for every season of every TV show, as Folder Actions don't handle subfolder as far as I know.
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

That's part of the reason why Hazel exists. As I mentioned before, you should test the script outside of Hazel. It appears the problem you are running into is with the script itself.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Ok, I've changed my plans. I now am simply happy to have the script convert/remux based on file extension. I'll add to iTunes manually. For this, the script works, as below:

Code: Select all
if name extension of (info for theFile) is "mp4" then
   -- display dialog "Passing Through import - mp4" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "mkv" then
   -- display dialog "Passing Through import - mkv" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "m2ts" then
   -- display dialog "Passing Through import - m2ts" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as QuickTime movie with deleting without gui
   end tell
else if name extension of (info for theFile) is "avi" then
   -- display dialog "Converting import - avi" buttons {"OK"} default button 1
   tell application "iFlicks"
      import theFile as new Apple TV & iPad video with deleting without gui
   end tell
end if


Problem is, I tried to get it running on sub folders, and it didn't fire properly.

I created a rule to apply to the top level of my external HD, which said "File type is folder" then "Run rule on contents of folder", then "run embedded AppleScritpt" (which contained the script above).

Console tells me the script fires ok if I add a file called, say, "Breaking Bad.S01E01.mkv" to, say, External HD > TV Shows > Breaking Bad > Season 01, but it doesn't actually add the mkv to iFlicks for conversion. It's as if it now doesn't understand "theFile"
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

Read the sticky article about subfolders. You are combining rules in a way that doesn't make sense as outlined there.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Sorry, but I've given up.

I wish someone could explain to me in plain English how to do this.
MoodyM
 
Posts: 34
Joined: Tue Aug 13, 2013 7:36 am

PreviousNext

Return to Support