Close

Risultati da 1 a 3 di 3

Discussione: Error Applescript

  1. #1
    Approdato su Mac Peer L'avatar di acidrock
    Data Registrazione
    May 2009
    Località
    Torino
    Messaggi
    46

    Error Applescript

     

    Ciao ragazzi... mi sono dato un po' all'Apple Script

    Questi giorni, dopo molte ricerche ho creato lo script che vedete sotto.
    Funziona con iTunes (a parte che devo avviare lo script ogni volta che avvio iTunes) ma non funziona con un altro player, Ecoute. Mi da questo errore nella compilazione: Errore di sintassi Si attendeva “,” ma è stato trovato identificativo.

    Qualcuno potrebbe aiutarmi?!
    L'errore secondo Apple Script Editor si trova dove è in grassetto.

    Grazie!!!

    -- Ecoute Announcer
    -- by Aaron Harnly
    -- Feel free to modify and/or distribute this script

    property Announce_verbally : true
    -- if true, the script will speak out loud the name, artist,
    -- and album of each new song as it plays in Ecoute.



    property idle_time : 5
    -- idle_time determines how often, in seconds,
    -- the script will check for a new track being played.
    -- Shorter intervals will place the announcement closer
    -- to the start of songs, but incur a heavier load on the system.

    property quot : the ASCII character 34 -- Use &quot& to add a quotation mark.
    -- ***********************************
    -- *** Verbal Announcement Settings ***
    property verbal_announcement_name : "Now playing [NAME] "
    property verbal_announcement_artist : "by [ARTIST], "
    property verbal_announcement_album : "from the album [ALBUM]."
    -- The verbal announcement is broken into three parts;
    -- the track name is always announced, while the artist
    -- and album are announced only if they have changed
    -- from the previous song.
    property volume_fade_step : 3
    -- volume_fade step determines how quickly volume fades up & down.
    -- if you want the volume to fade up & down faster or slower,
    -- adjust this.
    property volume_during_announcement : 25
    -- volume_during_announcement sets the volume, from 0 to 100,
    -- of the music during the spoken announcement.
    -- Louder feels more continuous, but makes it harder to
    -- understand the voice.
    -- ***********************************



    global previous_track
    global previous_artist
    global previous_album

    global current_track
    global track_name
    global track_artist
    global track_album
    global track_comments

    on VerbalAnnounce()
    set the_announcement to my parseAnnouncement(verbal_announcement_name)
    -- always announce the new track name.
    if (track_artist is not equal to previous_artist) then
    set the_announcement to the_announcement ¬
    & my parseAnnouncement(verbal_announcement_artist)
    -- iff the artist has changed, announce the artist
    end if

    if (track_album is not equal to previous_album) then
    set the_announcement to the_announcement ¬
    & my parseAnnouncement(verbal_announcement_album)
    -- iff the album has changed, announce the album
    end if

    set the old_volume to my fade_volume(volume_during_announcement)
    -- this fades down the volume
    -- and simultaneously saves the previous volume.
    say the_announcement
    -- This it! Finally! We say something!
    set the old_volume to my fade_volume(old_volume)
    -- now we fade the volume back up to the previous setting.
    end VerbalAnnounce


    on run
    -- The first moment we run the app, do an announcement & update.
    -- This will launch Ecoute if it isn't already open,
    -- but not start it playing.
    -- After that, we loop & check for Ecoute to play a new song.
    tell application "Ecoute"
    set previous_track to "" -- the current track
    set previous_artist to "" -- set to null so that we'll announce it.
    set previous_album to "" -- set to null so that we'll announce it.
    end tell
    my doAnnounce()
    end run

    on idle
    -- this idle handler gets called every few seconds.
    -- We want to check if the current song has changed.
    -- Note that if Ecoute isn't running, we don't do anything.
    set EcouteOpen to false
    tell application "Finder"
    if (get name of every process) contains "Ecoute" then set EcouteOpen to true
    end tell
    if (EcouteOpen) then
    -- Only check with Ecoute if it is currently running
    tell application "Ecoute"
    if (the player state is playing) then

    if (the previous_track is not equal to the current track) then
    my doAnnounce()
    end if
    end if
    end tell
    end if
    return idle_time
    end idle

    on doAnnounce()
    my update()
    if (Announce_verbally) then
    my VerbalAnnounce()
    end if
    my finishupdate()

    end doAnnounce

    on update()
    tell application "Ecoute"
    set current_track to the current track
    set track_name to the name of the current_track as text
    set track_artist to the artist of the current_track as text
    set track_album to the album of the current_track as text
    set track_comments to the comment of the current_track as text
    end tell

    if (the track_artist is "Various" or the track_artist is "Various Artists") then
    -- on a compilation CD, the artist will be "Various Artists" or "Various"
    -- We look to see if the artist of this track might be in the track's comment.
    -- If so, we'll report the Comment as the artist.
    if (the track_comments is not "") then
    set the track_artist to the track_comments
    set the track_comments to ""
    else
    set the track_artist to "Various Artists"
    end if
    end if

    if (the track_album is "") then
    set the track_album to "unknown"
    end if
    if (the track_artist is "") then
    set the track_artist to "an unknown artist"
    end if
    end update

    on finishupdate()
    set previous_track to current_track
    -- We keep track of the last track we announced,
    -- so that while idling we can check to see if
    -- Ecoute has started playing a new track.
    -- We also keep track of the previous artist and album,
    -- so we don't repeat those needlessly next time.
    set previous_artist to the track_artist
    set previous_album to the track_album
    end finishupdate


    on parseAnnouncement(the_text)
    set oldDelims to AppleScript's text item delimiters
    -- NAME
    set AppleScript's text item delimiters to "[NAME]"
    set replaced_text to text items of the_text
    set AppleScript's text item delimiters to the track_name
    set replaced_text to replaced_text as text
    -- ARTIST
    set AppleScript's text item delimiters to "[ARTIST]"
    set replaced_text to text items of replaced_text
    set AppleScript's text item delimiters to the track_artist
    set replaced_text to replaced_text as text
    --ALBUM
    set AppleScript's text item delimiters to "[ALBUM]"
    set replaced_text to text items of replaced_text
    set AppleScript's text item delimiters to the track_album
    set replaced_text to replaced_text as text

    set AppleScript's text item delimiters to oldDelims
    return replaced_text
    end parseAnnouncement

    on fade_volume(final_volume)
    tell application "Ecoute"
    set old_volume to the sound volume -- remember previous volume
    set theVol to old_volume
    if (final_volume < theVol) then
    -- we need to step down the volume to the destination
    repeat while (final_volume < theVol)
    set sound volume to theVol
    set theVol to theVol - volume_fade_step
    end repeat
    else
    -- we need to step up the volume to the destination
    repeat while (final_volume > theVol)
    set sound volume to theVol
    set theVol to theVol + volume_fade_step
    end repeat
    end if
    set sound volume to final_volume -- make it exactly right
    end tell
    return old_volume -- send back the previous volume
    end fade_volume

  2. #2
    un Amico di Mac Peer L'avatar di flashcream
    Data Registrazione
    Apr 2005
    Località
    Bergamo
    Messaggi
    38,388
    questo script è stato scritto per itunes 2. (oggi siamo alla 9 e forse spiega come mai non faccia tutto quello che promette). vengo al punto.... penso che sostituire "itunes" con "ecoute" o altro, come hai fatto, non garantisca l'esecuzione dell'azione dello script. non conosco ecoute per dire altro, ma la vedo dura senza una conoscenza precisa di questo lettore e conseguentemente con una revisione sostanziale dello script.
    Ultima modifica di flashcream; 28-11-09 alle 16:58

  3. #3
    Approdato su Mac Peer L'avatar di acidrock
    Data Registrazione
    May 2009
    Località
    Torino
    Messaggi
    46
    Citazione Originariamente Scritto da flashcream Visualizza Messaggio
    questo script è stato scritto per itunes 2. (oggi siamo alla 9 e forse spiega come mai non faccia tutto quello che promette). vengo al punto.... penso che sostituire "itunes" con "ecouter" o altro, come hai fatto, non garantisca l'esecuzione dell'azione dello script. non conosco ecouter per dire altro, ma la vedo dura senza una conoscenza precisa di questo lettore e conseguentemente con una revisione sostanziale dello script.
    Ecco... quindi tolto tutti i miei dubbi, ho preso pezzi di codice e montato aggiungendo due o tre istruzioni. Su iTunes, anche se è la versione 9 funziona benissimo su Ecoute no appunto, pensavo anch'io, per "comandi" diciamo così di questo lettore.
    Comunque, grazie Flash, proverò a informarmi di più su Ecoute e far funzionare lo script!

    Buon sabato!

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  •