Friday, May 27, 2022

#1 2022-01-25 08:23:41 am

ldicroce
Member
Registered: 2017-11-25
Posts: 265

Editing PDF metadata using a script works, but not with Applet

Hi all,

I have a simple script that help me in editing metadata, such as:


Applescript:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"

on run
   set therecord to {Title:"LDC tile44", Author:"LDC auth44", Subject:"LDC subj44"}
   set posixPath to "/Users/ldicroce/Desktop/10_1016@j_devcel_2021_12_007.pdf"
   my setDocumentAttributes:therecord forPDFAt:posixPath    
end run

on setDocumentAttributes:attributeRecord forPDFAt:posixPath
   set thePath to current application's NSString's stringWithString:posixPath
   set thePath to thePath's stringByExpandingTildeInPath()
   display dialog "OK1a"
   set theUrl to current application's NSURL's fileURLWithPath:thePath
   display dialog "OK1b"
   set thePDFDoc to current application's PDFDocument's alloc()'s initWithURL:theUrl
   display dialog "OK1c"
   set theDict to current application's NSDictionary's dictionaryWithDictionary:attributeRecord
   thePDFDoc's setDocumentAttributes:theDict
   return thePDFDoc's writeToFile:thePath
end setDocumentAttributes:forPDFAt:

And , it works perfectly.
But if I export the script as Applet, then it stops always at this line:

Applescript:

set thePDFDoc to current application's PDFDocument's alloc()'s initWithURL:theUrl

The applet has full access to the disk and folders ....
Any help to overcome this?
Thanks.

L.

Last edited by ldicroce (2022-01-25 09:24:31 am)

Offline

 

#2 2022-01-25 09:30:44 am

ldicroce
Member
Registered: 2017-11-25
Posts: 265

Re: Editing PDF metadata using a script works, but not with Applet

It seems that the applet (but not the simple Apple script [.scpt]) triggers the following error:
PDFDocument doesn’t understand the “alloc” message.
-1708

any help ?

Offline

 

#3 2022-01-25 09:36:06 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1327

Re: Editing PDF metadata using a script works, but not with Applet

Your script doesn't include the Quartz framework. After including that, the script saved as an app worked for me.


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#4 2022-01-25 09:53:35 am

ldicroce
Member
Registered: 2017-11-25
Posts: 265

Re: Editing PDF metadata using a script works, but not with Applet

peavine wrote:

Your script doesn't include the Quartz framework. After including that, the script saved as an app worked for me.



Beautiful !!!! Thanks a million !!!
I was misguided (and I still don't understand) since the script was working fine, but the applet failed ....


Just in few words, when do I need to add use framework "Quartz" ?
Thanks again !

Offline

 

#5 2022-01-25 10:29:29 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 1327

Re: Editing PDF metadata using a script works, but not with Applet

ldicroce wrote:

Just in few words, when do I need to add use framework "Quartz" ?



I have trouble remembering what requires a particular framework, so when in doubt I check the documentation. I believe I only use the Quartz framework for PDF stuff, but the documentation describes this framework as:

Allow users to browse, edit, and save images, using slideshows and Core Image filters


2018 Mac mini - macOS Monterey - Script Debugger 8

Offline

 

#6 2022-01-25 12:27:17 pm

ldicroce
Member
Registered: 2017-11-25
Posts: 265

Re: Editing PDF metadata using a script works, but not with Applet

Thanks

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)