Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zqbobs

macrumors member
Original poster
Mar 10, 2009
64
18
I've searched for ways to do this online and in apps, without success. Most posts are years old, and it may be a dead topic. I would like to automatically print a filename (or better, path) as page header or footer when printing MacOS documents (Pages,Numbers,Keynote). Anyone know if that's possible and if so, how? I'm using Ventura on Intel Mac.
 
Printing a page header would be specific to the particular application and you would see the option in the print dialog under the application name. Notes and Safari can print headers. Pages, Numbers, and Keynote cannot.
 
Pages&company print headsets or footers. AFAIK you have at least 2 options to add a path and filename - sadly none of them is automatic, probably tha’s what @chabig refers to.

  • Launch Finder.
  • Select and right-click the file.
  • Press and hold the Option key from the keyboard.
  • Select Copy [file name] as Pathname.
  • Then paste into the footer or header.

Another option is using Applescript. You create a Pages template with a placeholder in the footer or header, e.g. [FilePath] and [FileName]. Then you need some Applescript which you run from the opened document.

property tagStr1 : "[FileName]"
property tagStr2 : "[FilePath]"


tell application "Pages"
tell front document


set theTagName to the tag of every placeholder text whose tag is equal to tagStr1
set theTagPath to the tag of every placeholder text whose tag is equal to tagStr2


set docName to name of it as text

set docPath to file of it as text


set docPath to (POSIX path of docPath) as text

if text -1 of docPath is equal to "/" then


-- trim trailing slash from package folder path

set docPath to text 1 thru -2 of (POSIX path of docPath) as text
end if

if
(count of theTagName) is not equal to 0 then

repeat
with i from 1 to count of theTagName


set thisTag to itemi of theTagName

set (every placeholder text whose tag is thisTag) to docName
end repeat
end
if



if (count of theTagPath) is not equal to 0 then
repeat
with i from 1 to count of theTagPath


set thisTag to itemi of theTagPath

set (every placeholder text whose tag is thisTag) to docPath
end repeat
end
if


end tell
end
tell

If you change [B]tell[/B] [I]application[/I] "Pages" to [B]tell[/B] [I]application[/I] "Numbers" (or Keynote, Word, …) you should be able to use this method in other programs.

nota bene: this is some code I found a long time ago on some discussion board - I’ll check later and will supply a reference link. I haven’t run this from the latest Pages version (so far), mainly because I switch all my correspondence/documentation/writing to plain text or LaTeX. 😃


EDIT: how the heck do I insert code from the Applescript editor here keeping the indentation and format?
 
Last edited:
It’s very easy in LibreOffice. Insert - Field - More Fields (shortcut ⌘F2) File name – Path/File name.
Example inserted into footer
footer.jpg
 
Thanks. My issue is that sometimes this happens e.g. above:
[B]tell[/B] [I]application[/I] "Pages" to [B]tell[/B] [I]application[/I]….
Does of course not happen when copy/paste from BBedit (or Textastic on iPadOS)... just recognised that this is restricted to inline code using [ICODE], something new every day 😀. Thanks again.
 
  • Like
Reactions: kryten2
Copy-paste from ScriptEditor, Insert code - AppleScript

InsertApplescript.jpg

Code:
[CODE=applescript]

AppleScript:
tell application "TextEdit"
    activate
end tell
 
  • Like
Reactions: kryten2
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.