2 votos

Ayuda para conseguir la instrucción condicional al final de esta secuencia de comandos, para que funcione correctamente

Básicamente, la función de este script es para convertir un archivo de vídeo a través del Apple TV compatible con el formato y, a continuación, elimine los archivos originales después de que se complete la conversión.

Estoy absolutamente en mi "whits final". Durante los últimos tres horas, he probado con todas las combinaciones posibles que podía pensar para obtener la instrucción condicional al final de la secuencia de comandos para que funcione correctamente.

Esta es la situación. Puedo descargar un montón de torrent los archivos de vídeo que en última instancia residen en el interior de una carpeta en mi disco duro llamado "Terminado". El 90% del tiempo, los vídeos descargados dentro de su propia carpeta que llamaremos "descargar video" carpeta. Cada ahora y entonces, me descarga un archivo de vídeo que no está contenida en su propia carpeta. Así que este vídeo descargado, ahora reside en el "Acabado" de la carpeta.

Al final de este script que estoy tratando de hacer la instrucción condicional que básicamente es.. Si el archivo descargado está dentro de "descargar video" de la carpeta que está dentro de "Terminado" en la carpeta..., a continuación, elimine la "descargar vídeo" en la carpeta que contiene el archivo de vídeo y otros archivos) <<-en esta parte de la secuencia de comandos funciona correctamente, PERO.. Si el vídeo descargado el archivo no está contenida en una carpeta de su propia y ahora es contenida por el "Acabado" de la carpeta... entonces, simplemente eliminar un archivo de vídeo único. <<- esta parte no funciona correctamente. No importa lo que yo trato, yo me quedo borrado de mi "Terminado" en la carpeta (que pasa a contener docenas de otras carpetas que quiero permanecer intacto)

Como una nota del lado, estoy bastante seguro de que he añadido algunos pasos en esta secuencia de comandos que no necesita ser añadido. El conjunto de secuencias de comandos de proceso LOL

property creationDate : (current date) - (minutes * 10)
property inputPath1 : alias "Macintosh HD:Users:Smokestack:Documents:Vuze Downloads:Finished:"
property outputPath1 : alias "Macintosh HD:Users:Smokestack:Music:iTunes:iTunes Media:Home Videos:"


set inputPath to POSIX path of inputPath1
set outputPath to POSIX path of outputPath1
set theIcon to path to resource "Apple_TV_Logo.png"

display dialog "     CONVERT VIDEO FOR APPLE TV" buttons {"Cancel", "Choose File"} default button 2 with icon theIcon
if the button returned of the result is "Choose File" then
    set theProcess to choose file with prompt "Choose Video Files To Convert For Apple TV" default location inputPath1
    set theFile to the result -- sets the variable to the name of the chosen file
    set theFile1 to theFile
    set deleteOriginalFolder to theFile -- used at the end of the script to delete the original video chosen
    tell application "System Events"
        set theName to name of theProcess -- get the name of the file to insert its value in the following lines
    end tell
    set outputPath2 to (outputPath & theName & ".m4v")
    display dialog "PLEASE BE PATIENT.  THIS PROCESS COULD TAKE UP TO 30 MINUTES TO COMPLETE" buttons {"OK"} default button 1 with icon theIcon giving up after 7

    set theFile to POSIX path of theFile
    set theFile to "-i " & quoted form of theFile & " -o " & quoted form of outputPath & quoted form of theName & ".m4v"
    do shell script "/Applications/HandBrakeCLI -Z \"AppleTV 3\" " & theFile
else
    return
end if

-- The Next Command... For Videos Added To iTunes To Be Immediately Available In Apple Tv, The Video Must Be Plyed, For At Least A Brief Second, First In iTunes

tell application "Finder"
    open (every item of outputPath1 whose creation date > creationDate)
end tell

delay 2

-- The Next Command... Closes The Video Window In iTunes

tell application "System Events"
    keystroke "." using command down
end tell

-- Below Is Where I'm Jammed Up

tell application "Finder"
    set deleteOriginalFolder to the container of deleteOriginalFolder
    if deleteOriginalFolder is not equal to inputPath1 then
        delete deleteOriginalFolder -- This Deletes The Original File And It's Containing Folder if it is located inside alias "Macintosh HD:Users:Smokestack:Documents:Vuze Downloads:Finished:"
    else
        if theFile1 is in inputPath1 then -- this is supposed to delete the original file only..  If it's container is  alias "Macintosh HD:Users:Smokestack:Documents:Vuze Downloads:Finished:"
            delete theFile1
        end if
    end if
end tell

display notification "Your Video Is Now In Your iTunes Home Videos Folder And Is Available To Be Watched With Apple Tv" with title "YOUR VIDEO CONVERSION HAS COMPLETED" sound name "submarine"

Estoy esperando que alguien puede me apunte en la dirección correcta.


ACTUALIZACIÓN:

Aquí es una versión del código que funciona a la perfección!! Esto fue tomado del Post de @Hurston que proporcionan las ediciones a mi código en su respuesta a mi post

Sólo un par de pequeñas modificaciones eran necesarias.

property creationDate : (current date) - (minutes * 10)
property inputPath1 : (path to documents folder as text) & "Vuze Downloads:Finished:"
property outputPath1 : (path to music folder as text) & "iTunes:iTunes Media:Home Videos:"

set inputPath to POSIX path of inputPath1
set outputPath to POSIX path of outputPath1
set theIcon to path to resource "Apple_TV_Logo.png"

display dialog "CONVERT VIDEO FOR APPLE TV" buttons {"Cancel", "Choose File"} default button 2 with icon theIcon
if the button returned of the result is "Choose File" then
    set theFile to choose file with prompt "Choose Video Files To Convert For Apple TV" default location (inputPath1 as alias)

    tell application "System Events"
        set theName to name of theFile
    end tell

    set outputPath2 to (outputPath & theName & ".m4v")

    display dialog "PLEASE BE PATIENT.  THIS PROCESS COULD TAKE UP TO 30 MINUTES TO COMPLETE" buttons {"OK"} default button 1 with icon theIcon giving up after 7
    set posixFile to POSIX path of theFile
    set posixFile to "-i " & quoted form of posixFile & " -o " & quoted form of outputPath2
    do shell script "/Applications/HandBrakeCLI -Z \"AppleTV 3\" " & posixFile
else
    return
end if

tell application "Finder"
    open (every item of folder outputPath1 whose creation date > creationDate)
end tell

delay 2

tell application "System Events"
    keystroke "." using command down
end tell

tell application "Finder"
    set deleteOriginalFolder to the container of theFile
    if (deleteOriginalFolder as text) is not equal to inputPath1 then
        delete deleteOriginalFolder
    else
        delete theFile
    end if
end tell

display notification "Your Video Is Now In Your iTunes Home Videos Folder And Is Available To Be Watched With Apple Tv" with title "YOUR VIDEO CONVERSION HAS COMPLETED" sound name "submarine"

2voto

Karthik Ramachandran Puntos 4672

Como alguien nuevo a las secuencias de comandos, yo diría que este es un muy buen esfuerzo. Creo que el problema tiene que ver con la variable de clases (de un texto o alias), y tal vez algo de la confusión causada por variables redundantes, así que he cambiado el código un poco y poner comentarios en línea. No tengo handbreak instalado, así que me comentó que fuera parte, y ejecutar el script, y ahora elimina correctamente la carpeta que lo contiene (que no es el acabado de su carpeta) o el propio archivo. Por favor, ver más abajo.

property creationDate : (current date) - (minutes * 10)
property inputPath1 : (path to documents folder as text) & "Vuze 
Downloads:Finished:" --I used the built-in path to command in case something in the path changes, and set this to text rather than an alias, because text is easier to manipulate. Also, it wouldn't compile on my system because that path doesn't exist, but as text, it will compile.
property outputPath1 : (path to music folder as text) & "iTunes:iTunes Media:Home Videos:" --same as above

set inputPath to POSIX path of inputPath1
set outputPath to POSIX path of outputPath1
set theIcon to path to resource "Apple_TV_Logo.png"

display dialog "CONVERT VIDEO FOR APPLE TV" buttons {"Cancel", "Choose File"} default button 2 with icon theIcon
if the button returned of the result is "Choose File" then
    set theFile to choose file with prompt "Choose Video Files To Convert For Apple TV" default location (inputPath1 as alias) --I changed theProcess to theFile, for simplicity later on
    --set theFile to the result --What was theProcess is already this alias, you set it in the step above. No need to create another variable with the exact same data
    --set theFile1 to theFile --This is the third time you've assigned a variable to the same thing. Unnecessary.
    --set deleteOriginalFolder to theFile -- This is the fourth time... unnecessary

tell application "System Events"
    set theName to name of theFile
end tell

set outputPath2 to (outputPath & theName & ".m4v")

display dialog "PLEASE BE PATIENT.  THIS PROCESS COULD TAKE UP TO 30 MINUTES TO COMPLETE" buttons {"OK"} default button 1 with icon theIcon giving up after 7
set posixFile to POSIX path of theFile --changed this from theFile to posixFile for clarity, and in case you need theFile later on.
set posixFile to "-i " & quoted form of posixFile & " -o " & quoted form of outputPath2 --same as above
do shell script "/Applications/HandBrakeCLI -Z \"AppleTV 3\" " & posixFile --same as above 
else--else statement is unnecessary, because the "Cancel" button returns a "User Cancelled" message to the script, but I left this
    return
end if

-- The Next Command... For Videos Added To iTunes To Be Immediately Available In Apple Tv, The Video Must Be Plyed, For At Least A Brief Second, First In iTunes

tell application "Finder"
    open (every item of folder outputPath1 whose creation date > creationDate) --added the word folder because outputPath1 is now text
end tell

delay 2
-- The Next Command... Closes The Video Window In iTunes

tell application "System Events"
    keystroke "." using command down
end tell

-- Below Is Where I'm Jammed Up

tell application "Finder"
    set deleteOriginalFolder to the container of theFile --changed deltedOriginalFolder to theFile
    if (deleteOriginalFolder as text) is not equal to inputPath1 then 
--I added the "as text" to make sure the comparison would work
        delete deleteOriginalFolder -- This Deletes The Original File And It's Containing Folder if it is located inside alias "Macintosh HD:Users:Smokestack:Documents:Vuze Downloads:Finished:"
    else
        --if (theFile as text) inputPath1 then -- don't need the if statement because you've already checked above to see if it's in it's own folder. just delete the file
        delete theFile
        --end if
    end if
end tell

display notification "Your Video Is Now In Your iTunes Home Videos Folder And Is Available To Be Watched With Apple Tv" with title "YOUR VIDEO CONVERSION HAS COMPLETED" sound name "submarine"

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X