• 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: FastScripts and script editor discrepancies
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: FastScripts and script editor discrepancies


  • Subject: Re: FastScripts and script editor discrepancies
  • From: Phil Stokes <email@hidden>
  • Date: Thu, 03 Nov 2016 06:59:05 +0700


On 23 Jun 2016, at 14:38, Shane Stanley <email@hidden> wrote:

Meanwhile, if you want to display tabulated data under 10.11, stick this in a library and use it (but if you're running Script Debugger, it must be version 6):

use AppleScript version "2.5" --  10.11 or later
use framework "Foundation"
use framework "AppKit"
use framework "Carbon" -- AEInteractWithUser() is in Carbon
use scripting additions
property returnCode : missing value

its showMessage:"21212" withTitle:"Read Me" textMaxWidth:350 withButtons:{"OK", "Cancel"}

on showMessage:theMessage withTitle:boldBit textMaxWidth:maxWidth withButtons:buttonsList
-- make attributed string system font with monospaced digits
set fontSize to current application's NSFont's systemFontSizeForControlSize:(current application's NSRegularControlSize)
set theFont to current application's NSFont's monospacedDigitSystemFontOfSize:fontSize weight:(current application's NSFontWeightRegular)
set attsDict to current application's NSDictionary's dictionaryWithObject:theFont forKey:(current application's NSFontAttributeName)
set attString to current application's NSAttributedString's alloc()'s initWithString:theMessage attributes:attsDict
-- make a text field to hold the message
set theField to (current application's NSTextField's alloc()'s initWithFrame:{{0, 0}, {100, 20}})
tell theField
(its setEditable:false)
(its setBordered:false)
its setDrawsBackground:false
its (cell()'s setWraps:true)
its setPreferredMaxLayoutWidth:maxWidth
its setAttributedStringValue:attString
end tell
-- make it fit; needs to be done on the main thread
my performSelectorOnMainThread:"fitToSizeView:" withObject:theField waitUntilDone:true
-- make sure we have permission
set theError to current application's AEInteractWithUser(-1, missing value, missing value) -- -1 is kAEDefaultTimeout
if theError is not 0 then error "User interaction disallowed" number theError
-- create an alert 
set theAlert to current application's NSAlert's alloc()'s init()
tell theAlert
its setMessageText:boldBit
repeat with anEntry in buttonsList
(its addButtonWithTitle:anEntry)
end repeat
its setAccessoryView:theField
end tell
-- show the alert; needs to be done on the main thread
my performSelectorOnMainThread:"showTheAlert:" withObject:theAlert waitUntilDone:true
set buttonNumber to returnCode mod 1000 + 1 -- where 1 = right-most button
set buttonName to item buttonNumber of buttonsList
return buttonName
end showMessage:withTitle:textMaxWidth:withButtons:

on showTheAlert:theAlert
-- check we are running in foreground
if not (current application's NSThread's isMainThread()) as boolean then error "This handler must be called on the main thread." from current application
set my returnCode to theAlert's runModal()
end showTheAlert:

on fitToSizeView:aView
aView's setFrameSize:(aView's fittingSize())
end fitToSizeView:



The latest beta release of Sierra (10.12.2) has scotched this. 

It appears that the monospacedDigitSystemFontOfSize part in the line

set theFont to current application's NSFont's monospacedDigitSystemFontOfSize:fontSize weight:(current application's NSFontWeightRegular)

now results in some weird unicode character being inserted instead of a tab space. I’ve tried substituting the line with a fixed width fonts, but then I’m back to square 1 with the tabs all misaligned. Any suggestions?


Best


Phil





 _______________________________________________
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: FastScripts and script editor discrepancies
      • From: Shane Stanley <email@hidden>
    • Re: FastScripts and script editor discrepancies
      • From: Shane Stanley <email@hidden>
  • Next by Date: Re: FastScripts and script editor discrepancies
  • Next by thread: Re: FastScripts and script editor discrepancies
  • Index(es):
    • Date
    • Thread