On Apr 13, 2024, at 3:59 PM, list_email--- via Skim-app-users
<[email protected]> wrote:
>
>> There are various bounds properties for pages in the Skim AppleScript
>> dictionary. there is a ?bounds?, ?media bounds? and ?content bounds?. In
>> particular, the latter one especially detects the white margins of the page.
>> The other two are properties of the PDF that can also be changed (in
>> particular the ?bounds? for the crop box).
>>
>> Note that by default the page bounds are not saved by Skim, as they are part
>> of the PDF data which we leave alone. So you need to export with embedded
>> note to have it saved. That can also be done from AppleScript.
>>
>> Christiaan
>
> Ok, this is great—exporting with notes is the key. This works by manual
> manipulation with Skim, leaving a comfortably tiny amount of white space.
> I’ll try to whip up my non-existent Applescript skills to see if I can
> automate this.
>
> Jerry
With help from an AI and after studying the Skim dictionary, I have concocted
the following AppleScript. After some runs with erratic behavior including
opening the wrong file (a file already open in Skim but not in the source
folder) and actually working correctly exactly one time, it now _mostly_,
passes one file unmodified and one file over-cropped on the RHS but unchanged
on the other sides. Sometimes both are passed unchanged, and once one was
correctly cropped and the other was unchanged. This all from the same
AppleScript code.
The “log” command writes
PDF Bounds: 08305950
PDF Bounds: 08305950
Thanks for any comments. I hope this isn’t too OT.
BTW I am doing this work mostly in Visual Studio Code with the AppleScript
extension, but I can’t report any different behavior while using Apple’s Script
Editor or when running it as an app.
Jerry
-- Set the source folder where the PDF files are located
set sourceFolder to choose folder with prompt "Select the folder containing the
PDF files to crop"
-- Set the destination folder where the cropped images will be saved
set destinationFolder to choose folder with prompt "Select the folder to save
the cropped images"
-- Loop through all the PDF files in the source folder
tell application "Finder"
set pdfFiles to every file of sourceFolder whose name ends with ".pdf"
repeat with pdfFile in pdfFiles
-- Open the PDF file in Skim.app
tell application "Skim"
open pdfFile
-- Crop the PDF file using the "content bounds" method
tell front document
set contentBounds to content bounds of page 1 -- of front page
set bounds of page 1 to contentBounds
end tell
log "PDF Bounds: " & (contentBounds as string)
-- Save the cropped PDF file to the destination folder with
embedded notes
set fileName to name of pdfFile
set croppedFileName to (destinationFolder as string) & fileName
save front document in croppedFileName as "PDF With Embedded Notes"
close front document without saving
end tell
end repeat
end tell
-- Display a message when the script is finished
display dialog "All PDF files have been cropped and saved to the destination
folder with embedded notes."
_______________________________________________
Skim-app-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-users