Applescript works as an app but not as a droplet - Ventura

applescript droplet not working in ventura 13.7.8


I compiled this helpful applescript for flattening pdfs by @VikingOSX from Preview - Export to PDF is grayed out....… - Apple Community and saved it as an application. It works great when launched first (although I did have to codesign it with a self-signed certificate to keep it from constantly asking for permission to access my desktop). However, it doesn't work as a droplet or if I right-click on a pdf and choose it as the application to "open with"


My ultimate goal is actually to create a quickaction that will launch the app and have the app flatten the pdf I've selected, but even getting it to work as a droplet would help


(i recently upgraded from BigSur to Ventura so I'm a little new to Ventura. I tested a very simple droplet that just flashes a message when a document is dropped on it and that worked, so it's not as if Ventura can't run droplets)

Posted on Aug 27, 2026 8:53 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 28, 2026 10:37 AM

As noted, the referenced script is only written to handle being double-clicked on. There's nothing in there that tells it what to do with dropped files, so it just ignores them.


Additionally, as suggested, this would be relatively easy to rewrite as a shortcut/Quick Action.


But if you really want a droplet, it's pretty simple to change the script to accept opened files.


The original script is just one list of commands to run.

This revised script puts all of that heavy-lifting into a handler (I called doIt, but it can be anything you like), and adds two handlers - one for when the app is launched, and one for when it has files dropped on it. Both of these handlers simply identify the file (either by referencing what was dropped, or by asking the user for a file) and then passes that to the doIt() handler.


Untested, but it's pretty straightforward:


-- this gets run when the app is launched directly:
on run
	set thisPDF to POSIX path of (choose file of type "com.adobe.pdf" default location (path to desktop) without invisibles) as text
	doit(thisPDF)
end run

-- this gets run when files are dropped on the app:
on open (theFiles)
	repeat with each_file in theFiles
		doit(each_file)
	end repeat
end open

-- this is the pre-existing script with a file passed in based on the above:
on doit(theFile)
	set basename to (NSString's stringWithString:thisPDF)'s stringByDeletingPathExtension()
	set basename_sfx to basename's stringByAppendingString:SUFFIX
	set outPDF to basename_sfx's stringByAppendingPathExtension:"pdf"
	set outURL to NSURL's fileURLWithPath:outPDF
	
	set inURL to NSURL's fileURLWithPath:thisPDF
	set pdf to PDFDocument's alloc()'s initWithURL:inURL
	
	set {{x, y}, {w, h}} to (pdf's pageAtIndex:0)'s boundsForBox:(current application's kPDFDisplayBoxMediaBox)
	set pdict to (NSDictionary's dictionaryWithObject:outURL forKey:(current application's NSPrintJobSavingURL))'s mutableCopy()
	pdict's setObject:(current application's NSPrintSaveJob) forKey:(current application's NSPrintJobDisposition)
	pdict's setObject:outURL forKey:(current application's NSPrintJobSavingURL)
	set printInfo to NSPrintInfo's alloc()'s initWithDictionary:pdict
	
	printInfo's setVerticalPagination:(current application's NSPrintingPaginationModeAutomatic)
	printInfo's setJobDisposition:(current application's NSPrintSaveJob)
	printInfo's setTopMargin:36.0
	printInfo's setBottomMargin:36.0
	printInfo's setLeftMargin:36.0
	printInfo's setRightMargin:36.0
	printInfo's setPaperSize:(current application's NSMakeSize(w, h))
	
	set printOp to pdf's printOperationForPrintInfo:printInfo scalingMode:0 autoRotate:false
	printOp's setShowsPrintPanel:false
	printOp's setShowsProgressPanel:false
	printOp's runOperation()
	return
end doit



You'll need to play the same code signing shenanigans again with the new version of the script

6 replies
Question marked as Top-ranking reply

Aug 28, 2026 10:37 AM in response to Cathy Choy

As noted, the referenced script is only written to handle being double-clicked on. There's nothing in there that tells it what to do with dropped files, so it just ignores them.


Additionally, as suggested, this would be relatively easy to rewrite as a shortcut/Quick Action.


But if you really want a droplet, it's pretty simple to change the script to accept opened files.


The original script is just one list of commands to run.

This revised script puts all of that heavy-lifting into a handler (I called doIt, but it can be anything you like), and adds two handlers - one for when the app is launched, and one for when it has files dropped on it. Both of these handlers simply identify the file (either by referencing what was dropped, or by asking the user for a file) and then passes that to the doIt() handler.


Untested, but it's pretty straightforward:


-- this gets run when the app is launched directly:
on run
	set thisPDF to POSIX path of (choose file of type "com.adobe.pdf" default location (path to desktop) without invisibles) as text
	doit(thisPDF)
end run

-- this gets run when files are dropped on the app:
on open (theFiles)
	repeat with each_file in theFiles
		doit(each_file)
	end repeat
end open

-- this is the pre-existing script with a file passed in based on the above:
on doit(theFile)
	set basename to (NSString's stringWithString:thisPDF)'s stringByDeletingPathExtension()
	set basename_sfx to basename's stringByAppendingString:SUFFIX
	set outPDF to basename_sfx's stringByAppendingPathExtension:"pdf"
	set outURL to NSURL's fileURLWithPath:outPDF
	
	set inURL to NSURL's fileURLWithPath:thisPDF
	set pdf to PDFDocument's alloc()'s initWithURL:inURL
	
	set {{x, y}, {w, h}} to (pdf's pageAtIndex:0)'s boundsForBox:(current application's kPDFDisplayBoxMediaBox)
	set pdict to (NSDictionary's dictionaryWithObject:outURL forKey:(current application's NSPrintJobSavingURL))'s mutableCopy()
	pdict's setObject:(current application's NSPrintSaveJob) forKey:(current application's NSPrintJobDisposition)
	pdict's setObject:outURL forKey:(current application's NSPrintJobSavingURL)
	set printInfo to NSPrintInfo's alloc()'s initWithDictionary:pdict
	
	printInfo's setVerticalPagination:(current application's NSPrintingPaginationModeAutomatic)
	printInfo's setJobDisposition:(current application's NSPrintSaveJob)
	printInfo's setTopMargin:36.0
	printInfo's setBottomMargin:36.0
	printInfo's setLeftMargin:36.0
	printInfo's setRightMargin:36.0
	printInfo's setPaperSize:(current application's NSMakeSize(w, h))
	
	set printOp to pdf's printOperationForPrintInfo:printInfo scalingMode:0 autoRotate:false
	printOp's setShowsPrintPanel:false
	printOp's setShowsProgressPanel:false
	printOp's runOperation()
	return
end doit



You'll need to play the same code signing shenanigans again with the new version of the script

Aug 28, 2026 10:20 AM in response to Cathy Choy

Do you want that script you reference to be made into an Apple Shortcut so you can right-click n-tuple PDFs in the Finder, and then select Quick Actions > Flatten PDFs? I don't have Ventura installed to test, but do have Sonoma, Sequoia, and Tahoe… which should be sufficient?


That current AppleScript/Objective-C solution was not written as a drop target, but an interactive open file chooser, so dropping files on the compiled app would do nothing.

Aug 28, 2026 7:23 AM in response to Cathy Choy


The reason your script works when launched directly but fails as a droplet or an "Open With" target comes down to how AppleScript handles incoming files. 

When you double-click a standard applet, it triggers a run handler. However, when you drop files onto an app or use "Open With", macOS strictly looks for an on open handler. If that handler isn't explicitly defined in the script, the dropped files are ignored, and nothing happens. 

Since your ultimate goal is a Quick Action (which is much more convenient than a droplet), you can achieve this easily using Automator without needing to codesign or maintain a standalone application applet.

Applescript works as an app but not as a droplet - Ventura

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.