• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: stringWithContentsOfURL works when it's a script, not when it's an app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stringWithContentsOfURL works when it's a script, not when it's an app


  • Subject: Re: stringWithContentsOfURL works when it's a script, not when it's an app
  • From: Shane Stanley <email@hidden>
  • Date: Wed, 05 Oct 2016 12:43:25 +1100

On 5 Oct. 2016, at 12:21 pm, Steve Mills <email@hidden> wrote:

Now stringWithContentsOfURL no longer works. It returns error:

The file “blah.html” couldn’t be opened.

Any ideas why this is failing?

It's hard to know -- do you mean Apple's Script menu?

I saved this as an app:

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

set mainUrl to current application's |NSURL|'s URLWithString:"http://apple.com"
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

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: stringWithContentsOfURL works when it's a script, not when it's an app
      • From: Steve Mills <email@hidden>
References: 
 >stringWithContentsOfURL works when it's a script, not when it's an app (From: Steve Mills <email@hidden>)

  • Prev by Date: stringWithContentsOfURL works when it's a script, not when it's an app
  • Next by Date: Saving in photoshop CS6 with option
  • Previous by thread: stringWithContentsOfURL works when it's a script, not when it's an app
  • Next by thread: Re: stringWithContentsOfURL works when it's a script, not when it's an app
  • Index(es):
    • Date
    • Thread