Opening Share sheet

Hi there,

Does anyone know how to open a share sheet from AppleScript, especially for the Notes App?

I found some sources how to do it with Mail but it doesn’t work with Notes.

	set aService to current application's NSSharingService's sharingServiceNamed:("com.apple.Notes.SharingExtension")
	aService's setDelegate:me
	aService's setSubject:"Subject"
	set shareItems to current application's NSMutableArray's alloc()'s initWithObjects:"Body text to share"
	aService's performWithItems:shareItems
tell application "System Events" to tell ¬
	application process "Notes" to tell ¬
	menu bar 1 to tell ¬
	menu bar item "File" to tell ¬
	menu "File" to tell ¬
	menu item "Share" to tell ¬
	menu "Share" to tell ¬
	menu item "AirDrop" to if ¬
	exists then click

Hi CJK,

thanks for your suggestion. I know about that way, but it’s not localization proof. Apple even has changed localizations in the same language over the time.

set theSource to path to application "Notes"
set file_loc to localized string "file" in bundle theSource --> fichier
set share_loc to localized string "Share" in bundle theSource -- "Partager"

tell application "System Events" to tell ¬
	application process "Notes" to tell ¬
	menu bar 1 to tell ¬
	menu bar item file_loc to tell ¬
	menu 1 to tell ¬
	menu item share_loc to tell ¬
	menu 1 to tell ¬
	menu item "AirDrop" to if ¬
	exists then click

As far as I know there is no need to grab file_loc, the File menu is always the 3rd one so

set theSource to path to application "Notes"
set share_loc to localized string "Share" in bundle theSource -- "Partager"

tell application "System Events" to tell ¬
	application process "Notes" to tell ¬
	menu bar 1 to tell ¬
	menu bar item 3 to tell ¬
	menu 1 to tell ¬
	menu item share_loc to tell ¬
	menu 1 to tell ¬
	menu item "AirDrop" to if ¬
	exists then click

would be sufficient.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 4 décembre 2019 15:22:39

1 Like