I'm trying to renaming PDF files with it's PDF content but just don't work. That's how i'm trying:
- Set Variable “pdfPath” to Text “%TriggerValue%”
- execute applescript:
tell application "Keyboard Maestro Engine"
set filePath to get variable "pdfPath"
if filePath is "'" then
return "Error: No se pudo obtener la ruta del archivo"
end if
log "Procesando archivo: " & filePath
end tell
tell application "Preview"
try
-- Cerrar documentos previos
close every document saving no
-- Abrir el archivo PDF
open POSIX file filePath
activate
delay 1
-- Copiar todo el contenido
tell application "System Events"
tell process "Preview"
keystroke "a" using command down
delay 0.5
keystroke "c" using command down
end tell
end tell
delay 0.5
set PDFContent to the clipboard
close every document saving no
-- Buscar el número de identificación
set idNumber to do shell script "echo " & quoted form of PDFContent & " | grep -oE '[0-9]{5,12}'"
if idNumber is not "" then
-- Obtener directorio y construir nuevo nombre
set fileDirectory to do shell script "dirname " & quoted form of filePath
set newName to idNumber & " HC.pdf"
-- Renombrar el archivo
try
do shell script "mv " & quoted form of filePath & " " & quoted form of (fileDirectory & "/" & newName)
tell application "Keyboard Maestro Engine" to set variable "ScriptResult" to "Archivo renombrado a: " & newName
on error errMsg
tell application "Keyboard Maestro Engine" to set variable "ScriptResult" to "Error al renombrar: " & errMsg
end try
else
tell application "Keyboard Maestro Engine" to set variable "ScriptResult" to "No se encontró número de identificación"
end if
on error errMsg
-- Asegurar que se cierren los documentos
close every document saving no
tell application "Keyboard Maestro Engine" to set variable "ScriptResult" to "Error: " & errMsg
end try
end tell
tell application "Preview" to quit
- Notification “%ExecutingMacro%”
I'm not a programmer just getting help from claude 3.5. Thanks all of u for the help