La pregunta básica es:
¿Cómo puedo pasar un nombre de archivo al módulo de búsqueda de Spotlight en Automator?
El problema esencial:
Tengo cientos de alias rotos repartidos por un directorio en particular en mi disco duro. Los archivos originales TODAVÍA EXISTEN, pero por alguna razón los alias han perdido su conexión. Me gustaría reemplazarlos todos con enlaces simbólicos, para que Rsync pueda respaldarlos.
Aquí hay un ejemplo reducido de una carpeta con alias rotos:
Ahora, aquí hay un ejemplo de un subdirectorio que contiene los originales de algunos de los alias rotos, así como copias adicionales del MISMO alias, que aún apuntan a otra ubicación para sus originales:
Y, por último, aquí hay una imagen de un directorio que contiene los archivos maestros de algunos de los alias que estaban ubicados en las 2 ubicaciones anteriores:
Así que lo que tengo que hacer es:
Uso Automator siempre que puedo y Applescript donde debo hacerlo. Antes de la respuesta que provocó estas ediciones, mi flujo de trabajo hizo lo siguiente:
Ahora, va un poco más lejos pero con algunos problemas:
Con suerte, esto será suficiente detalle para finalmente llegar a una solución que funcione. Puedo decir que está muy cerca.
Si simplemente desea pasar un nombre de archivo a la acción Spotlight
Pasar el nombre del archivo de una acción a una variable establecida Acción
ESTA ES UNA ACTUALIZACION
Uso de acciones de Automator y Applescript para almacenar propiedades para su posterior recuperación:
La idea aquí es que la primera acción escribe un archivo applescript en la carpeta de documentos.
El script se usará para almacenar información que obtengamos en el camino y luego recuperarla más tarde en la acción final de Applescript.
Hacemos esto porque necesitamos pasar el script final con múltiples bits de información. Lo cual no podemos hacer con las variables normales en Automator.
Las acciones.
La secuencia de comandos.
set script_text to MakeScript()
my RunMaker(script_text)
on RunMaker(script_text)
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt"
set file_path to POSIX path of file_path as string
store script script_text in file_path with replacing
end RunMaker
on MakeScript()
script
property theBrokenAliasFolderPath : ""
property broken_alias_file_Paths : {}
property theOriginalFolderPath : ""
property Original_file_Paths : {}
property SearchfileNames : {}
end script
end MakeScript
2, Solicitar elementos del buscador: esto es para la carpeta Broken Alias.
3, ejecute Applescript:
(Las escrituras se realizan mediante Action Applescript que carga el script del archivo de almacenamiento. Esta será una especie de versión. Luego cambiará las propiedades en su versión y volverá a escribir el archivo reemplazando el anterior)
--WRITE OUT BROKEN ALIAS FOLDER PATH
on run {input, parameters}
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt" as alias
set script_text to load script file_path
set theBrokenAliasFolderPath of script_text to (POSIX path of (item 1 of input))
my RunMaker(script_text)
return input
end run
on RunMaker(script_text)
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt"
set file_path to POSIX path of file_path as string
store script script_text in file_path with replacing
end RunMaker
4, obtener el contenido de la carpeta:
5, elementos del buscador de filtros:
Todos: Tipo: es: otro: alias
6, Ejecute Applescript:
Escribe PATHS de alias rotos en una propiedad en el archivo de script de almacenamiento.
on run {input, parameters}
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt" as alias
set script_text to load script file_path
set broken_alias_file_Paths of script_text to input
my RunMaker(script_text)
return input
end run
on RunMaker(script_text)
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt"
set file_path to POSIX path of file_path as string
store script script_text in file_path with replacing
end RunMaker
7, Solicitar elementos del buscador: esto es para la carpeta de archivos originales.
8, ejecute Applescript:
Escribe la carpeta de archivos originales en una propiedad en el archivo de script de almacenamiento.
on run {input, parameters}
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt" as alias
set script_text to load script file_path
set theOriginalFolderPath of script_text to (POSIX path of (item 1 of input))
my RunMaker(script_text)
return input
end run
on RunMaker(script_text)
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt"
set file_path to POSIX path of file_path as string
store script script_text in file_path with replacing
end RunMaker
9, Ejecute Applescript:
Esto recupera la información del script de almacenamiento. Esto tomará la lista de rutas de los archivos de alias inactivos.
Pruebe y busque un archivo coincidente en la carpeta Archivos originales. Buscará todas las coincidencias pero ignorará los alias.
Elimine el antiguo archivo de alias (verifique primero que sea un archivo de alias)
Cree un enlace simbólico en la carpeta en la que se encontraba el alias anterior desde el archivo coincidente encontrado.
Solo se deben eliminar los archivos de alias. Si no se encuentra ningún archivo coincidente, el archivo de alias no se eliminará. Tampoco se creará un enlace simbólico.
.
set file_path to (path to documents folder as Unicode text) & "MyProperties.scpt" as alias
set theScript to load script file_path
--choose a search folder
set searchPath to quoted form of theOriginalFolderPath of theScript
set folderPath to quoted form of theBrokenAliasFolderPath of theScript
set input to broken_alias_file_Paths of theScript
repeat with i from 1 to count of items of input
set this_item to item i of input
set aliasPath to this_item
#Get the the file name
set theFileName to "\\\"" & (do shell script "basename " & quoted form of (POSIX path of (this_item))) & "\\\"" as string
log theFileName
#search the searchPath for a matching file with the same name.
#NOTE: this will find all files with he same name. So We use last paragraph to get what should be the first one it finds.
set theOrigFilePath to paragraphs of (do shell script "mdfind -onlyin " & searchPath & " kMDItemFSName == \"" & theFileName & "\"")
if theOrigFilePath is not quoted form of "" then
repeat with i from 1 to count of items in theOrigFilePath
set this_item to item i of theOrigFilePath
log this_item
tell application "Finder"
#make sure we are pointing to an alais that will be deleted and not another symlink file. Otherwise the original file will be deleted.
set theKind to kind of ((POSIX file this_item) as alias)
if theKind is not equal to "Alias" then
set this_item to quoted form of (item i of theOrigFilePath)
my symLink(aliasPath, this_item)
end if
end tell
end repeat
end if
end repeat
on symLink(aliasPath, aOrigFilePath)
#move to trash the old alias file
set theOldAlias to aliasPath
tell application "Finder"
#make sure we are pointing to an alais that will be deleted and not another symlink file. Otherwise the original file will be deleted.
set theKind to kind of theOldAlias
set theNewFilePath to (POSIX path of (aliasPath)) as string
if theKind is equal to "Alias" then
delete theOldAlias
log "ln -s " & aOrigFilePath & space & (quoted form of theNewFilePath)
#create the symlink
do shell script "ln -s " & aOrigFilePath & space & (quoted form of theNewFilePath)
end if
end tell
end symLink
Prueba primero... úsalo bajo tu propio riesgo y todo eso...
Por lo general, "alias roto" se refiere a un alias donde el archivo original ya no existe. He usado este script para encontrar alias como ese:
set l to {}
tell application "Finder"
try
alias files of entire contents of (POSIX file "/Users/username" as alias)
result as list
on error
return
end try
repeat with f in result
try
original item of contents of f
on error
--move contents of f to trash
set end of l to POSIX path of (f as text)
end try
end repeat
end tell
set text item delimiters to linefeed
l as text
Si la secuencia de comandos encuentra los alias que desea reemplazar los enlaces simbólicos, guarde las líneas relevantes de la salida en un archivo de texto. Luego intente ejecutar un script de shell como este:
cat /tmp/aliases.txt | while IFS= read -r f; do
original=$(find ~/directory/with/original/files -name "${f##*/}" | head -n1)
echo "$f:$original"
# rm "$f"; ln -s "$original" "$f"
done
alias files of entire contents of (POSIX file "/Users/username" as alias)
solo obtiene una lista de todos los archivos de alias en /Users/username
. También puede intentar extraer las rutas originales de las bifurcaciones de recursos con algo como cat example.txt\ alias/..namedfork/rsrc | strings
.Podría usar mdfind
cuál es la versión de línea de comandos de Spotlight en un subíndice de shell en Automator. Puede pasar variables hacia y desde este script/comando a través de stdin y stdout.
EDITAR si no desea intentar usar ningún comando de shell:
¿Intentó establecer un valor de una variable en Automator, luego hizo clic con el botón derecho en el cuadro de entrada de Spotlight y eligió "Nueva variable..." en la parte inferior de la lista emergente?
beroe
markhunte
JVC
markhunte