use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set {s, err} to current application's NSString's stringWithContentsOfURL:mainUrl encoding:(current application's NSUTF8StringEncoding) |error|:(reference)
display dialog (s as text)
It runs fine from Apple's Script menu and from the FastScripts menu. As does the following when saved as an applet (but not as a .scpt):
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
my notifyWithTitle:"A test" andSubtitle:"More stuff here"
on notifyWithTitle:theTitle andSubtitle:theSubtitle
set theNSUserNotification to current application's NSUserNotification's alloc()'s init()
theNSUserNotification's setTitle:theTitle
theNSUserNotification's setInformativeText:theSubtitle
theNSUserNotification's setHasReplyButton:true
theNSUserNotification's setOtherButtonTitle:"No way"
set theNSUserNotificationCenter to current application's NSUserNotificationCenter's defaultUserNotificationCenter()
theNSUserNotificationCenter's setDelegate:me -- so we can force it to appear while app is frontmost
theNSUserNotificationCenter's deliverNotification:theNSUserNotification
end notifyWithTitle:andSubtitle:
on userNotificationCenter:anNSUserNotificationCenter shouldPresentNotification:anNSUserNotification
return true -- show it, regardless of what app is frontmost
end userNotificationCenter:shouldPresentNotification:
on removeNotification()
set theNSUserNotificationCenter to current application's NSUserNotificationCenter's defaultUserNotificationCenter()
theNSUserNotificationCenter's removeAllDeliveredNotifications()
end removeNotification