tell application "PDFpen"
set POSIXPath to path of front document
end tell
--set POSIXPath to "~/Documents/test.pdf"
tell application "System Events"
set theName to name of disk item POSIXPath
set theContainer to path of (container of disk item POSIXPath)
end tell
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 26 janvier 2021 12:13:40
tell application "PDFpen"
set POSIXPath to path of front document
end tell
-- set POSIXPath to "~/Documents/test.pdf"
set aList to my decoupe(POSIXPath, "/")
set theName to item -1 of aList
set theContainer to my recolle(items 1 thru -2 of aList, "/")
#=====
on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as string
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 26 janvier 2021 18:02:45
The Pages.app doesn’t provide path property. But you can get Posix path of front document using file property of document and Posix path command of Standard Additions.
tell application "Pages"
set POSIXPath to POSIX path of (get file of front document)
end tell
One question, is the only way to get just the file path for an app which does not provide a path property is to use the code that Yvan Koenig provided?
I don’t know if I understood your question correctly, but I think the answer is obvious: the script from @Yvan Koenig is only for applications that have a path property to access their document file.
There is no single way for applications that do not have this property, since everything depends on the implementation of the application by the developer. Although, so far I have come across only those applications that use one of two: file and path. You can put in try block: first attempt with path property, on error - second attempt with file property, on nested error - return the error description.
set appName to "Pages"
tell application appName
try
return path of front document
on error
try
return POSIX path of (get file of front document)
on error errorMessage
return errorMessage
end try
end try
end tell