Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:15:08+00:00 2026-06-12T12:15:08+00:00

I wrote a simple applescript to automatically add files into iTunes and fill the

  • 0

I wrote a simple applescript to automatically add files into iTunes and fill the metadata. When I run it directly from the editor it works but running it from iTunes and I will get “AppleEvent Timed Out”.

Here’s the code:

set mainFolder to choose folder

tell application "Finder"
    -- Loop through all shows
    set shows to every folder of mainFolder
    repeat with show from 1 to count of shows

        -- Set Show Name
        set showName to name of item show of shows

        -- Set Artist
        display dialog "Who is the artist for " & showName & "?" default answer showName
        set showArtist to the text returned of the result

        -- Set Genre
        display dialog "What is the genre for " & showName & "?" default answer ""
        set showGenre to the text returned of the result

        -- Loop through all season
        set seasons to every folder in item show of shows
        repeat with season from 1 to count of seasons

            set seasonName to name of item season of seasons

            -- Set Season Number
            set seasonNumber to text 1 thru ((offset of "-" in seasonName) - 2) of seasonName as integer

            -- Set Year
            display dialog "What year was Season " & seasonNumber & " of " & showName & " in?" default answer "2012"
            set showYear to the text returned of the result

            -- Set Season Name      
            set seasonName to text ((offset of "-" in seasonName) + 2) thru ((offset of "." in seasonName) - 1) of seasonName as text

            -- Set Total Episodes in Season
            set totalEpisodes to count of every file in item season of seasons

            -- Loop through all episodes
            set episodes to every file in item season of seasons
            repeat with episode from 1 to count of episodes

                set episodeName to name of item episode of episodes

                -- Set Episode Number
                set episodeNumber to text 1 thru ((offset of "-" in episodeName) - 2) of episodeName as integer

                -- Set Episode Name
                set episodeName to text ((offset of "-" in episodeName) + 2) thru ((offset of "." in episodeName) - 1) of episodeName as text

                tell application "iTunes"
                    set newAddition to (add (item episode of episodes as alias))
                    tell newAddition
                        set video kind to TV show
                        set name to episodeName
                        set album to seasonName
                        set track number to episodeNumber
                        set track count to totalEpisodes
                        set disc number to "1"
                        set disc count to "1"
                        set show to showName
                        set season number to seasonNumber
                        set episode number to episodeNumber

                        -- Manual Entries
                        set artist to showArtist
                        set genre to showGenre
                        set year to showYear


                        -- Change episode ID based on season and episode number
                        if (seasonNumber < 10) then
                            if (episodeNumber < 10) then
                                set episode ID to ("S0" & seasonNumber as text) & "E0" & episodeNumber as text
                            else
                                set episode ID to ("S0" & seasonNumber as text) & "E" & episodeNumber as text
                            end if
                        else
                            if (episodeNumber < 10) then
                                set episode ID to ("S" & seasonNumber as text) & "E0" & episodeNumber as text
                            else
                                set episode ID to ("S" & seasonNumber as text) & "E" & episodeNumber as text
                            end if
                        end if

                    end tell -- End newAddition
                end tell -- End iTunes
            end repeat -- End Episode Repeat
        end repeat -- End Season Repeat
    end repeat -- End Show Repeat
end tell -- End Finder Repeat
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:15:10+00:00Added an answer on June 12, 2026 at 12:15 pm

    Here is how I solved it:

    Save as an app instead of a script.

    I got the solution from here:
    http://forums.ilounge.com/applescripts-itunes-mac/245120-need-help-add-tracks-files-via-applescript.html

    I have no clue why it’s doing that, I’ve tried using try-catch, timeout… still didn’t work. It works as an app though?!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote simple test add 100 items to [Collection] read 1000000 times from [Collection]
I wrote a simple function, that makes emacs add matching quotes (so when I
I've wrote simple RMI code to learn how it works. While everything works fine
I wrote simple NMEA parser and I'm reading latitude and longitude from GPS. Values
I wrote simple class in JS witch works, but i had problem when i
I wrote simple aplication for android. It works great in emulator. But when I
I wrote simple monte-carlo π calculation program in Python, using multiprocessing module. It works
I wrote simple code for deleting all entries from android calendar,but it didn't delete
I wrote this simple test code, by adapting a piece from a book, to
I wrote simple android app with bugs. When open second activity from menu- android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.