Benches macOS

2

Import Video's into iTunes with apple script an set video kind

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I'm working on an apple script that you can drop files on and it will open Quicktime, save the file(s) as a self contained .mov and then add the new .mov file(s) to iTunes.

The part I'm not able to get working is setting the video kind after adding the file.

How to you select the track(video) you just imported into itunes and define meta data?

Here is the main part of the code:

tell application "QuickTime Player"

run

open the_mov

if (can export front document as QuickTime movie) then

repeat

if ((get load state of front document) = complete) then

try

save self contained front document in (new_file & ".mov")

close document 1

tell application "iTunes"

if media_type is "Movie" then set media_type to movie

if media_type is "Music Video" then set media_type to music video

if media_type is "TV Show" then set media_type to TV show

launch

add (new_file & ".mov")

set sel to selection

set video kind of sel to media_type

end tell

exit repeat

on error the_error

if the_error is "A file by that name already exists." then

set new_file to (new_file & " - 1") as string

else

activate

display dialog the_error giving up after 30

exit repeat

end if

end try

end if

end repeat

else

display dialog "QuickTime is not able to convert this file: " & (get name of (info for thisItem without size)) buttons "Ok" default button 1 with icon caution

end if

end tell

2 replies

Sign in or join Beachball Help to reply.

  1. 0

    Camelot

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    The most obvious problem is the line:

    set video kind of sel to media_type

    where:

    set sel to selection

    In iTunes (as in many apps), 'selection' will return a list. That's because you may have more than one item selected. Even if there is only one item selected, you still get a list - just a list containing one item.

    You cannot set 'video kind' of a list. You might be able to set the video kind of items
    within the list, but that's not what you're asking iTunes to do. That would look something like:

    set sel to selection

    repeat with eachTrack in sel

    set video kind of of eachTrack to media_type

    end repeat

    That will iterate through the selected items which will get you closer.

    At the end of the day, though, even that approach isn't the right solution to your question since you're relying on something unstable like 'selection. The real solution is to take the reference returned by the
    add command:

    ...

    set newTrack to add (new_file & ".mov")

    set video type of newTrack to media_type

    This works because
    add returns a reference to the newly-added item and this can be used to target that object. There is no guarantee that 'selection' will point to the item you think it is.

  2. 0

    crozer

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thank you...

    This is my first apple script, and I need all the help I can get.