Created
April 1, 2025 13:52
-
-
Save pilotmoon/6d6da41f18c310b5d3cadb59a642d7d0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- #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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment