Friday, October 22, 2021

#1 2021-09-29 01:27:42 am

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 673
Website

Open PDF at specified page

Previously I was able to open pdf documents at a given page,

Applescript:

Tell app "system events" to set getUrl to URL of alias posixPathPdf
Open location (getUrl & "#page=5" as text)

But this opens just the pdf, not anymore at the page I want

Offline

 

#2 2021-09-29 04:05:43 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2092

Re: Open PDF at specified page

Applescript:


set pdfHFS to (choose file of type "com.adobe.pdf") as text

tell application "System Events" to set getUrl to URL of file pdfHFS
tell application "Safari" to open location getUrl & "#page=5"


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2021-09-29 03:48:44 pm

akim
Member
Registered: 2010-04-04
Posts: 139

Re: Open PDF at specified page

When I attempted to run the  script, the  following command fails to even open the pdf document.

Applescript:

tell application "Safari" to open location getUrl & "#page=5")

The following command opened the pdf document, but did not open the document at page 5

Applescript:

open location getUrl & "#page=5")

Offline

 

#4 2021-09-30 08:48:48 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 901

Re: Open PDF at specified page

I have test this script in Script Editor on Mojave and for me it works.

Applescript:

property pageNumber : "#page=150"

set theURL to "https://nathangrigg.com/images/2012/AppleScriptLanguageGuide.pdf"

tell application "Safari"
   make new document with properties {URL:(theURL & pageNumber)}
end tell


if you are the expert, who will you call if its not your imagination.

Offline

 

#5 2021-09-30 10:02:16 am

kerflooey
Member
Registered: 2011-07-07
Posts: 208

Re: Open PDF at specified page

KniazidisR's script works fine for me in Catalina.

Offline

 

#6 2021-09-30 12:17:18 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2092

Re: Open PDF at specified page

akim wrote:

When I attempted to run the  script, the  following command fails to even open the pdf document.

Applescript:

tell application "Safari" to open location getUrl & "#page=5")

The following command opened the pdf document, but did not open the document at page 5

Applescript:

open location getUrl & "#page=5")


There was no need to add a parenthesis to my script. I don’t know, it looks like it’s your carelessness. Or. trolling, which I will somehow survive.


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#7 2021-09-30 01:03:19 pm

akim
Member
Registered: 2010-04-04
Posts: 139

Re: Open PDF at specified page

KniazidisR,
Sorry for the confusion. The opening parenthesis was accidentally left out when I submitted the line of code. No trolling was intended.

Fredrik71,
When I ran your script, Safari  successfully downloaded the pdf as a file. It however did open the pdf to the targeted page in the browser, or otherwise.

I am running Catalina.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)