I just need a simple app where is possible to preview a pdf, select a text in the pdf and rename the file with this selection. I download all the time pdfs and need to rename them.
I thought it would make an interesting challenge for a PopClip Extension. Here’s what I put together:
-- #popclip
-- name: Rename PDF
-- icon: iconify:gg:rename
-- required apps: [com.apple.Preview]
-- language: applescript
-- AppleScript to rename the currently active PDF in Preview
set newFileName to "{popclip text}.pdf"
tell application "Preview"
-- Get the front document (the active PDF)
set theDoc to front document
set oldFilePath to path of theDoc
-- Close the document so the file is no longer locked by Preview
close theDoc
end tell
tell application "Finder"
-- Convert the path to an alias
set oldFileAlias to POSIX file oldFilePath as alias
set parentFolder to container of oldFileAlias
-- Rename the file
set name of oldFileAlias to newFileName
-- Grab the new alias to the renamed file
set newFileAlias to (parentFolder as text) & newFileName as alias
end tell
-- Re-open the renamed file in Preview
tell application "Preview"
open newFileAlias
activate
end tell
(The above block is an extension snippet — select it then click “Install Extension” in PopClip.)
This is limited to working in Preview only but could probably be adapted for other PDF apps.
My preferred PDF program is PDF Expert. Would simply plugging in its name for Preview in the snippet work? Second question: could a variation of this work with quickview, thereby not having to open the file?
An uninformed thought: PDFExpert has a setting to either have documents open in tabs vs. open in windows. I wonder if having it set to open in windows would help. (I forget which it defaults to “out of the box” but I’ve found open in tabs annoying and switched to open in windows a long time ago.
I too use PDF expert and seeing that NIck has ruled it out for this solution, I have planned a workaround. I am going to use hazel to open the downloaded pdf in preview even though its not default, then I can rename the pdf using this extension and close. later whenever i want to open the file it will open in the PDF expert default.
@nick is it possible to make some format changes as well to the filename as part of the extension… such as have sentence style capitalize though the text selected may be all caps?