• 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: Small change to script causes Script Editor to crash - Yosemite
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Small change to script causes Script Editor to crash - Yosemite


  • Subject: Re: Small change to script causes Script Editor to crash - Yosemite
  • From: Shane Stanley <email@hidden>
  • Date: Sun, 26 Oct 2014 18:01:56 +1100

On 26 Oct 2014, at 5:00 pm, Lists <email@hidden> wrote:

The entire script, unchanged is:

tell application "Safari"
try

Delete that first try and its end try -- it's just making the script continue when it shouldn't. The part you commented out was catching this error.

And remove the second 'tell application "Safari"' line -- none of that code addresses Safari.

But it's a rather slow and roundabout way of doing things in Yosemite. Here's an alternative that takes less than 0.01 seconds, as opposed to nearly half-a-second:

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit" -- for NSPasteboard

tell application "Safari"
if not (exists document 1) then error "No document is open."
set theURL to URL of document 1
try
get theURL
on error
error "The front document has no URL."
end try
set thisTitle to name of document 1
end tell
-- make link NSURL
set linkURL to current application's NSURL's URLWithString:theURL
-- make dictionary of text attributes: the NSURL, blue color, single underline
set theNSDictionary to current application's NSDictionary's dictionaryWithObjects:{linkURL, current application's NSNumber's numberWithUnsignedInteger:(current application's NSSingleUnderlineStyle), (current application's NSColor's blueColor())} forKeys:{current application's NSLinkAttributeName, current application's NSUnderlineStyleAttributeName, current application's NSForegroundColorAttributeName}
-- make attributed string containing the link
set theNSAttributedString to current application's NSAttributedString's alloc()'s initWithString:thisTitle attributes:theNSDictionary
-- get the clipboard
set theNSPasteboard to current application's NSPasteboard's generalPasteboard()
-- clear it
theNSPasteboard's clearContents()
-- put the link on it
theNSPasteboard's writeObjects:{theNSAttributedString}

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

 _______________________________________________
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

References: 
 >Small change to script causes Script Editor to crash - Yosemite (From: Lists <email@hidden>)

  • Prev by Date: Small change to script causes Script Editor to crash - Yosemite
  • Next by Date: Re: click using option down button 2 of window 1
  • Previous by thread: Small change to script causes Script Editor to crash - Yosemite
  • Next by thread: dock position
  • Index(es):
    • Date
    • Thread