Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

カテゴリー: System

mapboxSpeech Sample

Posted on 9月 27, 2019 by Takaaki Naganoya

mapboxが提供しているMapBoxSpeechフレームワークを呼び出すAppleScriptです。

mapboxは地図系の各種機能をWeb APIで提供しています。その一環としてGithub上でNatural-sounding text-to-speech Frameworkを提供しており、これをAppleScriptから呼び出してみました。

Github上のサンプルコードでは、AppleScript(Xcode上のプロジェクト)から呼び出すサンプルも掲載されているのですが、通常のScript EditorやScript Debugger上から呼び出す方法は掲載されていませんでした(しかも、サンプルそのままだと動く気配がないんですが、、、)。

# Xcode上で作成したアプリケーションだと、MapboxSpeech.Frameworkが、組み込んだアプリケーション側のInfo.plist内の指定のエントリに書かれているAccess tokenを読み込んでREST APIにアクセスできるとか。単体でAppleScriptからFrameworkを呼び出すような使い方は想定していなかったようです>サンプル

そこで、実際にmapboxにサインアップして、API Key(というか、プロジェクト単位でのToken)を取得、実際にGithub上で公開されているフレームワークをmacOS用にビルドし、通常のAppleScriptから呼び出してみました。

以下のアプレットは実行すると実際に日本語サンプル(たぶん)の文章を読み上げてくれます。実際に本Script(アプレットではなく)をAppleScriptとしてご自分の環境で動かすためには、Frameworkをインストールし、Script Debugger上で動かす(macOS 10.14以降)か、SIPを解除した環境(macOS 10.14以降)でスクリプトエディタ上で実行することになります。その際には、mapboxのWebサイト上でサインアップしてご自分のAccess tokenを取得してください。サインアップすると公開Access tokenを取得できますが、そちらではなく個別のプロジェクトをWebサイト上で作成して(Test AppleScriptとか)、そちらのAccess tokenを利用してください。

–> Download MapboxSpeech.framework(To ~/Library/Frameworks/)

–> mapboxSpeech Sample Run-Only(Code-Signed Executable Applet with Framework)

……で、実際にサンプル文章を読み上げてみたところ、英文なのに英文っぽくない日本語みたいな発音で、ちょっと「ナニコレ?」と思ってしまいましたが、冗談半分で日本語テキストをパラメータに指定してみたら、ちゃんと日本語を読み上げるのでビビりました。

この手のWebサービスで日本語対応はしておらず、英語+ヨーロッパの数カ国語のみサポートというのが普通です。

OS標準のsayコマンドよりも形態素解析が弱いようなので、文節ごとに読点(、)を入れてあげる必要はありますが、それでも日本語のテキストを読み上げてしまうのにはちょっと驚かされました。

AppleScript名:mapboxSpeech Sample.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/09/27
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "MapboxSpeech" –https://github.com/mapbox/mapbox-speech-swift
use framework "AVFoundation"
use scripting additions

on run
  set theOptions to current application’s MBSpeechOptions’s alloc()
  
theOptions’s initWithText:"こんにちは、私の名前は、「ながのや」 です。"
  
  
set speechSynthesizer to current application’s MBSpeechSynthesizer’s alloc()’s initWithAccessToken:"xx.xxX.X_XXxxxxxXXXXXxXxXXxxX"
  
set theURL to speechSynthesizer’s URLForSynthesizingSpeechWithOptions:theOptions
  
set theData to the current application’s NSData’s dataWithContentsOfURL:theURL
  
  
set aAudioPlayer to current application’s AVAudioPlayer’s alloc()’s initWithData:theData |error|:(missing value)
  
aAudioPlayer’s prepareToPlay()
  
aAudioPlayer’s setNumberOfLoops:0
  
aAudioPlayer’s setDelegate:me
  
aAudioPlayer’s play()
end run

–音楽再生の終了のDelegate Methodを取得
on audioPlayerDidFinishPlaying:anAudioplayer successfully:aFlag
  tell current application to quit
end audioPlayerDidFinishPlaying:successfully:

★Click Here to Open This Script 

Posted in REST API Sound Text to Speech | Tagged 10.12savvy 10.13savvy 10.14savvy | Leave a comment

TTSで日本語数値読み上げ

Posted on 9月 26, 2019 by Takaaki Naganoya

桁数の大きな数値のText To Speech(TTS)読み上げのAppleScriptです。

# 日本語環境における枝葉的な(マニアックな)数値表現の仕様に関する話であり、他の言語では関係ない話です。漢字文化圏で使われる数値表現のようですが、たとえば中国や韓国で使われている数値桁表現との間で厳密な互換性があるかといった確認は行なっておりません

実行前に日本語TTS読み上げ音声の「Otoya」あるいは「Kyoko」をインストールしておいてください。

まず、AppleScriptが指数表示なしに表現できる数値は10^9程度で、それを超えると指数表示になります。

ただし、指数表示になった数値を数値文字列に変換するノウハウは全世界的に共有されており、そのためのサブルーチン(Stringify)を呼び出すだけで済みます。

AppleScriptのsayコマンドでは「100兆」までの読み上げはそれっぽく実行してくれますが、「1000兆」になると読み上げ内容が数字の羅列になってしまいます。

これについても、大きな数値を日本語数値エンコーディング文字列に変換するサブルーチンを昔から公開しており(本Blog開設当初の11年前に掲載)、それを呼び出すだけで日本語数値表現文字列に変換できるため、読み上げられることでしょう。

Number Japanese English
1 一(いち) one
10 十(じゅう) ten
100 百(ひゃく) hundred
1000 千(せん) thousand
10000 万(まん) 10 thousand
100000 十万(じゅうまん) 100 thousand
1000000 百万(ひゃくまん) million
10000000 千万(せんまん) 10 million
100000000 億(おく) 100million
1000000000000 兆(ちょう) villion
1000000000000000 京(けい) thousand villion
100000000000000000 100京(ひゃっけい) trillion
10^24 丈(じょ)
10^28 穣(じょう)
10^52 恒河沙(ごうがしゃ)
10^56 阿僧祇(あそうぎ)
10^60 那由他(なゆた)
10^64 不可思議(ふかしぎ)
10^68 無量大数(むりょうたいすう)

とはいえ、「阿僧祇(あそうぎ、10^56)「那由多(なゆた、10^60)」といった数値桁を読み上げさせるとTTSが正しく読み上げてくれません。さすがにこんなにマニアックな数値表現はカバーしなくてよいでしょう。「丈(じょ)」「穣(じょう)」など似た音の桁が存在するあたり、これらは口に出して読み上げるものではなく、文字で読むためだけのものだと強く感じるものです。

AppleScript名:TTSで日本語数値読み上げ
repeat with i from 0 to 15
  set aNum to (10 ^ i)
  
say Stringify(aNum) of me using "Kyoko" –or "Otoya"
end repeat

on Stringify(x) — for E+ numbers
  set x to x as string
  
set {tids, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, {"E+"}}
  
if (count (text items of x)) = 1 then
    set AppleScript’s text item delimiters to {tids}
    
return x
  else
    set {n, z} to {text item 1 of x, (text item 2 of x) as integer}
    
set AppleScript’s text item delimiters to {tids}
    
set i to character 1 of n
    
set decSepChar to character 2 of n — "." or ","
    
set d to text 3 thru -1 of n
    
set l to count d
    
if l > z then
      return (i & (text 1 thru z of d) & decSepChar & (text (z + 1) thru -1 of d))
    else
      repeat (z – l) times
        set d to d & "0"
      end repeat
      
return (i & d)
    end if
  end if
end Stringify

★Click Here to Open This Script 

AppleScript名:TTSで日本語数値読み上げ v2
repeat with i from 15 to 70
  set aNum to (10 ^ i)
  
set jRes to encodeJapaneseNumText(aNum) of japaneseNumberEncodingKit
  
say jRes using "Kyoko" –or "Otoya"
end repeat

–課題:オーバーフローチェックを行っていない
set a to "102320120000108220010"
set jRes to encodeJapaneseNumText(a) of japaneseNumberEncodingKit
–> "1垓232京120兆1億822万10"

script japaneseNumberEncodingKit
  –数字文字列を日本語数値表現文字列に変換
  
on encodeJapaneseNumText(aNum)
    
    
set aText to Stringify(aNum) of me
    
set aText to aText as Unicode text
    
set dotText to "." as Unicode text
    
set upperDigit to ""
    
set lowerDigit to ""
    
    
–小数点の処理
    
if dotText is in aText then
      set b to offset of dotText in aText
      
set upperDigit to characters 1 thru (b – 1) of aText
      
set upperDigit to upperDigit as Unicode text
      
set lowerDigit to characters b thru -1 of aText
      
set lowerDigit to lowerDigit as Unicode text
    else
      set upperDigit to aText
    end if
    
    
    
set scaleList3 to {"", "万", "億", "兆", "京", "垓", "丈", "壌", "溝", "砂", "正", "載", "極", "恒河沙", "阿僧梢", "那由他", "不可思議", "無量大数"}
    
set splitDigit to 4
    
set nList to splitByDigit(upperDigit, splitDigit) of me
    
set nList to reverse of nList
    
    
set resText to ""
    
set digCount to 1
    
repeat with i in nList
      set b to (contents of i) as number
      
if b is not equal to 0 then
        set resText to (b as text) & item digCount of scaleList3 & resText
      end if
      
set digCount to digCount + 1
    end repeat
    
    
    
    
return resText & lowerDigit
    
  end encodeJapaneseNumText
  
  
–指定桁数で区切る
  
on splitByDigit(a, splitDigit)
    set aList to characters of a
    
set aList to reverse of aList
    
log aList
    
set resList to {}
    
set tempT to ""
    
set tempC to 1
    
repeat with i in aList
      set tempT to contents of i & tempT
      
if tempC mod splitDigit = 0 then
        set resList to {tempT} & resList
        
set tempT to ""
      end if
      
set tempC to tempC + 1
    end repeat
    
    
if tempT is not equal to "" then
      set resList to {tempT} & resList
    end if
    
    
resList
    
  end splitByDigit
  
  
  
  
on Stringify(x) — for E+ numbers
    set x to x as string
    
set {tids, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, {"E+"}}
    
if (count (text items of x)) = 1 then
      set AppleScript’s text item delimiters to tids
      
return x
    else
      set {n, z} to {text item 1 of x, (text item 2 of x) as integer}
      
set AppleScript’s text item delimiters to tids
      
set i to character 1 of n
      
set decSepChar to character 2 of n — "." or ","
      
set d to text 3 thru -1 of n
      
set l to count d
      
if l > z then
        return (i & (text 1 thru z of d) & decSepChar & (text (z + 1) thru -1 of d))
      else
        repeat (z – l) times
          set d to d & "0"
        end repeat
        
return (i & d)
      end if
    end if
  end Stringify
end script

★Click Here to Open This Script 

Posted in Number System Text Text to Speech | Tagged 10.12savvy 10.13savvy 10.14savvy | Leave a comment

NSApplicationにアクセス

Posted on 9月 21, 2019 by Takaaki Naganoya

NSApplicationにアクセスして実行環境の各種情報を取得するAppleScriptです。

プロセス関連のCocoaオブジェクトは何種類かありますが、

NSApplicationは実行環境そのもの、実行中のアプリケーションの内部情報を取得するオブジェクトのようです。他のアプリケーションをBundle IDで指定してNSApplicationを取得するような処理ができるのかと思って調べていたのですが、どーもできないっぽい。

AppleScriptからSystem Events経由でアクセスするいつものやり方で、取得できない要素はとくにないのですが、一長一短というか得意不得意があるという感じです。

AppleScript名:NSApplicationにアクセス.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/08/04
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set anApp to current application’s NSApplication’s sharedApplication()
–> <ScriptDebuggerApplication: 0x600002562d00>

anApp’s |running| as boolean
–> true

anApp’s enabledRemoteNotificationTypes()
–> 0

anApp’s mainMenu()
–>
(*
<NSMenu: 0x600001878240>
  Title: AMainMenu
  Open bounds: [t=1440, l=0, b=1440, r=0]
  Supermenu: 0x0 (None), autoenable: YES
  Items: (
"<NSMenuItem: 0x6000029294a0 Script Debugger, submenu: 0x6000018780c0 (Script Debugger)>",
"<NSMenuItem: 0x600002929aa0 File, submenu: 0x6000018789c0 (File)>",
"<NSMenuItem: 0x60000292ae20 Edit, submenu: 0x600001878a80 (Edit)>",
"<NSMenuItem: 0x60000291c240 View, submenu: 0x600001878c40 (View)>",
"<NSMenuItem: 0x60000291cfc0 Search, submenu: 0x600001878e80 (Search)>",
"<NSMenuItem: 0x60000291d5c0 Script, submenu: 0x600001878f00 (Script)>",
"<NSMenuItem: 0x60000291e700 Dictionary, submenu: 0x600001879040 (Dictionary)>",
"<NSMenuItem: 0x60000291ef40 Window, submenu: 0x600001879080 (Window)>",
"<NSMenuItem: 0x6000029285a0 Clippings, submenu: 0x600001878840 (Clippings)>",
"<NSMenuItem: 0x60000291f540 Scripts, submenu: 0x6000018791c0 (Scripts)>",
"<NSMenuItem: 0x60000291fc00 Help, submenu: 0x600001879340 (Help)>"
)
*)

anApp’s servicesMenu()
(*
<NSMenu: 0x600001878340>
  Title: Services
  Open bounds: [t=nan, l=6.95319e-310, b=nan, r=6.95319e-310]
  Supermenu: 0x6000018780c0 (Script Debugger), autoenable: YES
  Items: (
"<NSMenuItem: 0x60000e924cc0 Add to Wunderlist>",
"<NSMenuItem: 0x60000e927120 ATOK\U30a4\U30df\U30af\U30eb\U3067\U691c\U7d22>",
"<NSMenuItem: 0x60000e926f40 Evernote \U306b\U8ffd\U52a0>",
"<NSMenuItem: 0x60000e926a60 Finder\U3067\U60c5\U5831\U3092\U898b\U308b>",
"<NSMenuItem: 0x60000e927e40 Finder\U306b\U8868\U793a>",
"<NSMenuItem: 0x60000e9275a0 \U958b\U304f>",
"<NSMenuItem: 0x60000e9279c0 man\U30da\U30fc\U30b8\U3092\U30bf\U30fc\U30df\U30ca\U30eb\U3067\U958b\U304f>",
"<NSMenuItem: 0x60000e9246c0 \U30bf\U30fc\U30df\U30ca\U30eb\U306eman\U30da\U30fc\U30b8\U30a4\U30f3\U30c7\U30c3\U30af\U30b9\U3067\U691c\U7d22>",
"<NSMenuItem: 0x60000e924c00 \U30b9\U30c6\U30a3\U30c3\U30ad\U30fc\U30e1\U30e2\U3092\U4f5c\U6210>",
"<NSMenuItem: 0x60000e9249c0 \U30b9\U30dd\U30fc\U30af\U30f3\U30c8\U30e9\U30c3\U30af\U3068\U3057\U3066iTunes\U306b\U8ffd\U52a0>",
"<NSMenuItem: 0x60000e9244e0 \U30c6\U30ad\U30b9\U30c8\U3092\U7c21\U4f53\U5b57\U4e2d\U56fd\U8a9e\U306b\U5909\U63db>",
"<NSMenuItem: 0x60000e927a20 \U30c6\U30ad\U30b9\U30c8\U3092\U5168\U89d2\U306b\U5909\U63db>",
"<NSMenuItem: 0x60000e9276c0 \U30c6\U30ad\U30b9\U30c8\U3092\U534a\U89d2\U306b\U5909\U63db>",
"<NSMenuItem: 0x60000e9247e0 \U30c6\U30ad\U30b9\U30c8\U3092\U7e41\U4f53\U5b57\U4e2d\U56fd\U8a9e\U306b\U5909\U63db>",
"<NSMenuItem: 0x60000e925440 \U30de\U30c3\U30d7\U3092\U8868\U793a>",
"<NSMenuItem: 0x60000e926040 \U30a4\U30e1\U30fc\U30b8\U3092\U8aad\U307f\U8fbc\U3080>",
"<NSMenuItem: 0x60000e925ec0 \U30c7\U30b9\U30af\U30c8\U30c3\U30d7\U30d4\U30af\U30c1\U30e3\U3092\U8a2d\U5b9a>",
"<NSMenuItem: 0x60000e926c40 Skim\U3067URL\U3092\U958b\U304f>",
"<NSMenuItem: 0x60000e9266a0 Skim\U3067\U30d5\U30a1\U30a4\U30eb\U3092\U9<<description truncated at 2000 characters out of 4221>>"
*)

anApp’s mainWindow()
–> <ScriptWindow: 0x7ffd73e344c0>

anApp’s keyWindow()
–> <ScriptWindow: 0x7ffd73e344c0>

anApp’s |windows|()
(*
(NSArray) {
  <NSPanel: 0x600003139500>,
  <NSWindow: 0x60000312e500>,
  <MiniDebuggerWindow: 0x7ffd73e0b870>,
  <LNSFindWrapAroundWindow: 0x60000312b000>,
  <NSToolTipPanel: 0x7ffd73dee5e0>,
  <NSPanel: 0x600003104800>,
  <NSPanel: 0x600003104700>,
  <NSWindow: 0x60000315c800>,
  <NSColorPanel: 0x7ffce4aa99c0>,
  <NSWindow: 0x600003121d00>,
  <ScriptWindow: 0x7ffd73e344c0>,
  <NSComboBoxWindow: 0x7ffce4f27700>
}
*)

anApp’s dockTile()
–> <NSDockTile: 0x60000221db00>

anApp’s dockTile()’s |size|()
–> {width:128.0, height:128.0}

anApp’s dockTile()’s owner()
–> <ScriptDebuggerApplication: 0x600003f38480>

anApp’s dockTile()’s showsApplicationBadge()
–> false

anApp’s dockTile()’s badgeLabel()

anApp’s applicationIconImage()
–> <NSImage 0x60000573be40 Size={128, 128} Reps=( ……

anApp’s acceptsFirstResponder()
–> false

anApp’s becomeFirstResponder()
–> true

★Click Here to Open This Script 

Posted in Noification System | Tagged 10.12savvy 10.13savvy 10.14savvy NSApplication | Leave a comment

macOS 10.15beta関連

Posted on 8月 8, 2019 by Takaaki Naganoya

最初の10.15betaを使って3分で発覚した「aliasをposix pathに変換すると末尾がおかしくなるバグ」が修正されて一安心であるものの、Release時にさまざまなバグが再発する昨今のmacOS。

OSリリースの仕組みが会社組織的にうまく稼働していないことを感じます。とくに、CoreOSチーム。macOS 10.12でNSNotFoundの定義値を間違えたのは、間違いなくCoreOSチームなので。さらに、macOS 10.13の時にはBetaでうまく動いていたものがRelase時に動かなくなって言葉を失いました。

その後、macOS 10.13はOSごとまともに動いていなかったので(不具合に遭遇しない日はなかったので)、その反動でmacOS 10.14の自分的な評価がやたらといい今日このごろです。macOS 10.13みたいに「LAN上のファイル共有機能がいきなり効かなくなる」「日本語入力時に変換ウィンドウが消えなくなる」といった激しいバグには遭遇していません。ただ、10.13で壊滅的だったMail.appまわりのバグはいまだに信用できないので、10.14でもメールのやりとりはしないようにしています。
→ 最終バージョンの10.14.6の段階でメイン環境を移行し、目立った問題には遭遇していません

64bit Only環境の後ろ向きなメリット

各ビルドごとにmacOS 10.15 Betaのリリースノートがまとめて掲載されていますが、全体的に変更点が多くて驚かされます。

正直、macOS 10.15でこれだけOS内部のサービスやらフレームワークをいじくってしまうと、サードパーティ側がそれに追いつくのに相当の時間がかかるものと思われます。こんな大々的な変更を伴うアップデートを毎年行うべきものなのか疑問です。

ただ、64bitバイナリのみサポートするOSに移行するメリットが見えてきました。ユーザーにとって処理能力が上がるとかバッテリー寿命が伸びるとか、そうした目に見えやすいメリットではありません。

32bit版のバイナリを許容するということは、Apple側も32bit版バイナリとか32bitバイナリしか作れない古めの開発環境(互換開発環境とか?)に対応する必要があるわけで、32bitバイナリを検証し続けるほどのマンパワーがないんでしょうね。具体的にいえばCarbon系なんですが。

これまで、32bitバイナリ実行の検証に費やしていたパワーを、機能追加などに振り分けることにしたい、ということなのだと理解しました。ちなみに、2019年6月末でAppleのCarbon Dev MLが廃止になりました。MLのダウン時にはさんざん報告してもまともに対処しないくせに、こういう動きだけ素早いのはどうかと思います。

# AppleScriptの処理系はmacOS 10.7の時に64bit化されているため、64bit専用のOSになっても問題はありません。たまに間違った知識を吹聴している人がいるので念のため

BridgePlus.frameworkが(まだ)呼べない

実際に、Frameworkのバイナリ形式が変更になった(らしい)ので、macOS 10.15向けには野良Frameworkなどはビルドし直さないとダメなようです。いわく、32bitバイナリがあると文句を言われるのどうの。

目下、AppleScript関連でこの影響を最も受けているのがShane StanleyのBridgePlusライブラリ。内蔵のFrameworkをload frameworkコマンドで呼び出すと文句を言われます。

Shane次第ですが、おそらくこれはmacOS 10.15のリリースまでに解消されることでしょう(多分)。普通にXcode+10.14上でビルドしたしょーもないFrameworkが10.15上で動作(GundamのMS画像をCreateMLで学習させてZeonかEFSF所属かを判定させるFramework)しているので、それほど心配はしていません。

→ その後、Shaneからメールが来て「ちょっとこれ試してみて」と、xattrの削除を提案され、実際にやってみたらBridgePlusが動くようになりました。BridgePlusが動かなかったらけっこうきついので、一安心です

macOS 10.15 Beta5の変更点

macOS 10.15Beta5のRelease Notesに書かれている、重大な変更点が1つあります(処理系に手が加わっていないのにOS側のアップデートでいろいろ機能制限が出る今日このごろ)。

ネットワーク経由のAppleEvent実行、つまり現状ではLAN上のMac同士で、AppleScriptの常駐型のアプレットを起動して、ハンドラを一方から、あるいは相互に呼び合うことができます。いわゆるリモートAppleEventです。ここに手が加わりました。

この場合、呼ぶ側(Client)も呼ばれる側(Server)も、同じアカウントでログインしている必要がある、という変更です。この際に、「同じアカウント」というのがUser IDなのか、User名なのか、iCloud IDなのかが不明です。複数のmacOS 10.15betaマシンを用意しているわけではないのですが、物理的に可能で意味がありそうなのは同一のiCloud IDでしょうか(未検証)。

その後、macOS 10.14.6のマシン環境からRemote AppleEventsでLAN上のmacOS 10.15beta上で起動中のAppleScript Applet(常駐型)に向けてハンドラの呼び出しを行ってみたところ、同じユーザー名のアカウント同士で呼ぶことができました(使用中のiCloud IDも同じなので、何が基準なのか厳密にテストできていないんですけれども)。

AppleScript名:testRemoteEPPC
tell application "testApplet" of machine "eppc://user:xxxxxxxx@Yas-MBP.local"
  set aRes to testMe("ABCDEFG")
end tell

return aRes
–> "GFEDCBA"

★Click Here to Open This Script 

どのユーザーアカウントからのリモートAppleEvent接続でもアプリケーション(AppleScriptアプレット)が応答可能にするためには、受付側(Server)のMacでTerminalから設定コマンドを打ち込めとのこと。

defaults write /Library/Preferences/com.apple.AEServer RestrictAccessToUserSession -bool false

その後、システム環境設定の「共有」でリモートAppleEventsを禁止>許可と設定すると、他のユーザーセッションからでも制御(ハンドラ呼び出し)を受け付けるようです(未検証)。

リリースノートを一通り読んで、変更点がやたらと多いのと「罠」が多い(VPN接続時にAirDropが使用停止になる仕様など)ので、こなれるまで10.15は「待ち」だと感じています。最近のmacOSは(Beta版最終版よりも)Release時の出来がひどいので、1年かけて公式デバッグを行っているようなもの。しばらくmacOS 10.14を使い続けるのがベストでしょう。

Posted in System | Tagged 10.15savvy | Leave a comment

People Picker

Posted on 7月 11, 2019 by Takaaki Naganoya

ABPersonPickerでアドレスブックに登録のあるPerson(人)をダイアログ選択するAppleScriptです。

ずいぶんと前に作ってあったものの、活用できる機会がまったくなくて埃をかぶっていました。Alertダイアログ上に表示できないかと修正してみたものの、ABPersonPickerがWindowを要求するようで、書き換えてもうまく動かなかったために「誰か改良してくれるかもしれないし、掲載しとくかー」と、引っ張り出してきたものです。

本Scriptは人物(Person)1人を選択するものであるため、正確にいえば、Person Pickerですね。

人物の選択を行うための機能はAppleScriptには提供されていないため、一般的にはアドレスブックに登録されている全員の氏名を一括で取得してchoose from listで選択するといった話になることでしょう。

それよりは幾分マシではあるものの、使い勝手という面ではさっぱりです。アドレスブック(連絡先)でAppleScriptプラグインが(macOS 10.14で)使えなくなりましたが、このような代替案だったり、使い物にならない連作先.appの代わりにAddressBookフレームワークにアクセスしてPerson情報をしぼりこんでScriptを実行するようなプログラムを作ることになるでしょう。

連絡先(旧称アドレスブック)、カレンダー(旧称iCal)は「ただ動けばいい」ぐらいのぞんざいな作りなのが本当に残念です。


▲macOS 10.14.5(Dark Mode)上で実行したところ


▲ ABPersonPicker上でキーワードによる絞り込みもリアルタイムに行える

AppleScript名:People Picker
— Created 2017-12-20 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "AddressBook"

property NSView : a reference to current application’s NSView
property NSScreen : a reference to current application’s NSScreen
property NSButton : a reference to current application’s NSButton
property NSWindow : a reference to current application’s NSWindow
property ABPersonPicker : a reference to current application’s ABPersonPicker
property NSRectEdgeMaxX : a reference to current application’s NSRectEdgeMaxX
property NSWindowController : a reference to current application’s NSWindowController
property NSTitledWindowMask : a reference to current application’s NSTitledWindowMask
property NSRoundedBezelStyle : a reference to current application’s NSRoundedBezelStyle
property NSNormalWindowLevel : a reference to current application’s NSNormalWindowLevel
property NSBackingStoreBuffered : a reference to current application’s NSBackingStoreBuffered
property NSMomentaryLightButton : a reference to current application’s NSMomentaryLightButton

property windisp : false
property selectedPerson : missing value

on run
  set (my selectedPerson) to missing value
  
  
my performSelectorOnMainThread:"dispPeoplePicker:" withObject:(missing value) waitUntilDone:true
  
if (my selectedPerson) = missing value then return false
  
  
set firstName to (my selectedPerson’s |First|) as string
  
set lastName to (my selectedPerson’s |Last|) as string
  
  
return {lastName, firstName}
end run

on dispPeoplePicker:aParam
  set aWidth to 300
  
set aHeight to 100
  
choosePeople(aWidth, aHeight, "Result", "OK", 180) of me
end dispPeoplePicker:

on choosePeople(aWidth as integer, aHeight as integer, aTitle as text, aButtonMSG as text, timeOutSecs as number)
  set (my windisp) to true
  
  
–Buttonをつくる
  
set bButton to (NSButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(aWidth / 4, 0, aWidth / 2, 40)))
  
bButton’s setTitle:aButtonMSG
  
bButton’s setButtonType:(NSMomentaryLightButton)
  
bButton’s setBezelStyle:(NSRoundedBezelStyle)
  
bButton’s setKeyEquivalent:(return)
  
bButton’s setTarget:me
  
bButton’s setAction:("clicked:")
  
  
–NSViewをつくる
  
set aNSV to NSView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aHeight, aWidth))
  
aNSV’s addSubview:bButton
  
aNSV’s setNeedsDisplay:true
  
  
–NSWindowをつくる  
  
set aWin to makeWinWithView(aNSV, aWidth, aHeight, aTitle, 1.0)
  
  
–NSWindowControllerをつくる
  
set wController to NSWindowController’s alloc()
  
wController’s initWithWindow:aWin
  
wController’s showWindow:me
  
  
–People Pickerをつくる
  
set anAB to ABPersonPicker’s alloc()’s init()
  
anAB’s showRelativeToRect:(current application’s NSMakeRect(0, 0, 200, 200)) ofView:aNSV preferredEdge:(NSRectEdgeMaxX)
  
anAB’s setDelegate:(me)
  
  
–NSWindowの最前面表示  
  
aWin’s makeKeyAndOrderFront:me
  
  
set aCount to timeOutSecs * 10 –timeout seconds * 10
  
repeat aCount times
    if (my windisp) = false then
      exit repeat
    end if
    
delay 0.1
  end repeat
  
  
my closeWin:aWin
end choosePeople

–Button Clicked Event Handler
on clicked:aSender
  set (my windisp) to false
end clicked:

–make Window for Input
on makeWinWithView(aView, aWinWidth, aWinHeight, aTitle, alphaV)
  set aScreen to NSScreen’s mainScreen()
  
set aFrame to {{0, 0}, {aWinWidth, aWinHeight}}
  
set aBacking to NSTitledWindowMask
  
set aDefer to NSBackingStoreBuffered
  
  
— Window
  
set aWin to NSWindow’s alloc()
  (
aWin’s initWithContentRect:aFrame styleMask:aBacking backing:aDefer defer:false screen:aScreen)
  
  
aWin’s setTitle:aTitle
  
aWin’s setDelegate:me
  
aWin’s setDisplaysWhenScreenProfileChanges:true
  
aWin’s setHasShadow:true
  
aWin’s setIgnoresMouseEvents:false
  
aWin’s setLevel:(NSNormalWindowLevel)
  
aWin’s setOpaque:false
  
aWin’s setAlphaValue:alphaV –append
  
aWin’s setReleasedWhenClosed:true
  
aWin’s |center|()
  
aWin’s makeKeyAndOrderFront:(me)
  
  
— Set Custom View
  
aWin’s setContentView:aView
  
  
return aWin
end makeWinWithView

–close win
on closeWin:aWindow
  repeat with n from 10 to 1 by -1
    (aWindow’s setAlphaValue:n / 10)
    
delay 0.02
  end repeat
  
aWindow’s |close|()
end closeWin:

on personPicker:(aPicker) didChoosePerson:(aPerson) |property|:(aProperty) identifier:(anID)
  log {"personPicker:didChoosePerson:"}
  
log aPicker
  
log aPerson
  
log aProperty
  
log anID
  
copy aPerson to my selectedPerson
end personPicker:didChoosePerson:|property|:identifier:

on personPickerDidClose:(aPicker)
  log {"personPickerDidClose"}
  
set (my windisp) to false
end personPickerDidClose:

★Click Here to Open This Script 

Posted in dialog GUI System | Tagged 10.12savvy 10.13savvy 10.14savvy ABPersonPicker NSBackingStoreBuffered NSButton NSMomentaryLightButton NSNormalWindowLevel NSRectEdgeMaxX NSRoundedBezelStyle NSScreen NSTitledWindowMask NSView NSWindow NSWindowController | Leave a comment

アラートダイアログ上にTexViewを表示_ヘルプ付き_半透明_Float_SuppressionButtonつき

Posted on 7月 10, 2019 by Takaaki Naganoya

アラートダイアログ上にTextViewを表示して、指定のテキストを閲覧するAppleScriptです。

Xcode上でNSAlert.hを調べ、アラートダイアログに指定できる各種オプションを指定してみました。NSWindowLevelの変更は効いていないみたいですけれども。

AppleScript名:アラートダイアログ上にTexViewを表示_ヘルプ付き_半透明_Float_SuppressionButtonつき
— Created 2019-07-09 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property |NSURL| : a reference to current application’s |NSURL|
property NSFont : a reference to current application’s NSFont
property NSView : a reference to current application’s NSView
property NSAlert : a reference to current application’s NSAlert
property NSColor : a reference to current application’s NSColor
property NSTextView : a reference to current application’s NSTextView
property NSScrollView : a reference to current application’s NSScrollView
property NSUserDefaults : a reference to current application’s NSUserDefaults
property NSRunningApplication : a reference to current application’s NSRunningApplication
property NSModalPanelWindowLevel : a reference to current application’s NSModalPanelWindowLevel

property returnCode : 0
property supState : false

set asStr to do shell script "cal 2019"
set paramObj to {myMessage:"Main Message", mySubMessage:"Sub information", mes1:(asStr), mesWidth:450, mesHeight:200, fontName:"Courier", fontSize:11.0, suppressionMes:"Some Option"}

–my dispTextViewWithAlertdialog:paramObj–for debug
my performSelectorOnMainThread:"dispTextViewWithAlertdialog:" withObject:paramObj waitUntilDone:true

return (my supState)

on dispTextViewWithAlertdialog:paramObj
  –Receive Parameters
  
set aMainMes to (myMessage of paramObj) as string –Main Message
  
set aSubMes to (mySubMessage of paramObj) as string –Sub Message
  
set mesStr to (mes1 of paramObj) as string –Text Input field 1 Label
  
set aWidth to (mesWidth of paramObj) as integer –TextView width
  
set aHeight to (mesHeight of paramObj) as integer –TextView height
  
set aFontName to (fontName of paramObj) as string –TextView font name
  
set aFontSize to (fontSize of paramObj) as real –TextView font size
  
set aSupMes to (suppressionMes of paramObj) as string –Suppression Button Titile
  
  
–Detect Dark Mode
  
set dMode to retLIghtOrDark() of me
  
if dMode = true then
    set tvCol to 1
    
set tvAlpha to 0.8
    
set bCol to 0.1
    
set bAlpha to 0.8
    
set contentCol to (NSColor’s cyanColor())
  else
    set tvCol to 0
    
set tvAlpha to 0.1
    
set bCol to 1
    
set bAlpha to 0.5
    
set contentCol to (NSColor’s grayColor())
  end if
  
  
— Create a TextView with Scroll View
  
set aScroll to NSScrollView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight))
  
set aView to NSTextView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight))
  
set aColor to NSColor’s colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:(tvAlpha)
  
  
aView’s setRichText:true
  
aView’s useAllLigatures:true
  
aView’s setTextColor:(contentCol)
  
aView’s setFont:(NSFont’s fontWithName:aFontName |size|:aFontSize)
  
  
aView’s setDrawsBackground:false
  
  
  
aView’s setBackgroundColor:aColor
  
aView’s setOpaque:(false)
  
aView’s setString:mesStr
  
aScroll’s setDocumentView:aView
  
–aScroll’s setBorderType:(current application’s NSBezelBorder)
  
–aScroll’s setBorderType:(current application’s NSGrooveBorder)
  
–aScroll’s setBorderType:(current application’s NSLineBorder)
  
aScroll’s setBorderType:(current application’s NSNoBorder)
  
  
–Ruler
  
–aScroll’s setHasHorizontalRuler:(true)
  
–aScroll’s setRulersVisible:(true)
  
  
aView’s enclosingScrollView()’s setHasVerticalScroller:true
  
  
set anImage to current application’s NSImage’s imageNamed:(current application’s NSImageNameComputer)
  
  
— set up alert
  
set theAlert to NSAlert’s alloc()’s init()
  
tell theAlert
    its setIcon:(anImage)
    
    
–for Messages
    
its setMessageText:(aMainMes)
    
its setInformativeText:(aSubMes)
    
    
–for Buttons
    
its addButtonWithTitle:"OK"
    
its addButtonWithTitle:"Cancel"
    
    
–Add Accessory View
    
its setAccessoryView:(aScroll)
    
    
–for Help Button
    
its setShowsHelp:(true)
    
its setDelegate:(me)
    
    
its setAlertStyle:0 —-0…2
    
    
its setShowsSuppressionButton:(true) –「今後このメッセージを表示しない」チェックボックスを表示
    
    
set suppressionB to its suppressionButton
    
set myWindow to its |window|
  end tell
  
  
myWindow’s setOpaque:(false)
  
myWindow’s setBackgroundColor:(NSColor’s colorWithCalibratedWhite:(bCol) alpha:(bAlpha))
  
myWindow’s setLevel:(NSModalPanelWindowLevel)
  
  
suppressionB’s setTitle:(aSupMes)
  
suppressionB’s setState:(true) —default state
  
  
— show alert in modal loop
  
NSRunningApplication’s currentApplication()’s activateWithOptions:0
  
my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
  
if (my returnCode as number) = 1001 then error number -128
  
  
set my supState to (suppressionB’s state) as boolean
end dispTextViewWithAlertdialog:

on doModal:aParam
  set (my returnCode) to aParam’s runModal()
end doModal:

on alertShowHelp:aNotification
  display dialog "Help Me!" buttons {"OK"} default button 1 with icon 1
  
return false –trueを返すと親ウィンドウ(アラートダイアログ)がクローズする
end alertShowHelp:

–ダークモードの判定。ダークモード時:true、ライトモード時:falseが返る。System Eventsを使っていないのは、macOS 10.14以降対策(承認を取得しなくてもいいように)
on retLIghtOrDark()
  set curMode to (current application’s NSUserDefaults’s standardUserDefaults()’s stringForKey:"AppleInterfaceStyle") as string
  
return (curMode = "Dark") as boolean
end retLIghtOrDark

★Click Here to Open This Script 

Posted in Color dialog Font GUI Icon Image | Tagged 10.12savvy 10.13savvy 10.14savvy NSAlert NSColor NSFont NSModalPanelWindowLevel NSRunningApplication NSScrollView NSTextView NSURL NSUserDefaults | Leave a comment

アラートダイアログ上にTextViewを表示

Posted on 7月 8, 2019 by Takaaki Naganoya

アラートダイアログ上にTextViewを表示して、指定のテキストを閲覧するAppleScriptです。

とくにこれといって何か表示するものを思いつかなかったので、自分自身のソースコードを取得して表示しています。スクリプトエディタやScript Debugger上で実行した場合には自分自身のソースコードをテキストビュー上で表示します。

読み取り専用のスクリプトやアプレットで実行している場合にはソースコードを取得できません。何か適宜自分で表示させたいテキストを与えてみてください。

AppleScript名:アラートダイアログ上にTexViewを表示
— Created 2019-07-02 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "OSAKit"

property |NSURL| : a reference to current application’s |NSURL|
property NSFont : a reference to current application’s NSFont
property NSView : a reference to current application’s NSView
property NSAlert : a reference to current application’s NSAlert
property NSColor : a reference to current application’s NSColor
property NSTextView : a reference to current application’s NSTextView
property NSScrollView : a reference to current application’s NSScrollView
property NSRunningApplication : a reference to current application’s NSRunningApplication
property OSAScript : a reference to current application’s OSAScript

property returnCode : 0

–Get Self Source Code (a kind of joke)
set mePath to path to me
set asStr to getASsourceFor(mePath) of me

set paramObj to {myMessage:"Main Message", mySubMessage:"Sub information", mes1:(asStr), mesWidth:400, mesHeight:200, fontName:"HiraginoSans-W3", fontSize:11.0}

–my dispTextViewWithAlertdialog:paramObj–for debug
my performSelectorOnMainThread:"dispTextViewWithAlertdialog:" withObject:paramObj waitUntilDone:true

on dispTextViewWithAlertdialog:paramObj
  –Receive Parameters
  
set aMainMes to (myMessage of paramObj) as string –Main Message
  
set aSubMes to (mySubMessage of paramObj) as string –Sub Message
  
set mesStr to (mes1 of paramObj) as string –Text Input field 1 Label
  
set aWidth to (mesWidth of paramObj) as integer –TextView width
  
set aHeight to (mesHeight of paramObj) as integer –TextView height
  
set aFontName to (fontName of paramObj) as string –TextView font name
  
set aFontSize to (fontSize of paramObj) as real –TextView font size
  
  
— Create a TextView with Scroll View
  
set aScroll to NSScrollView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight))
  
set aView to NSTextView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight))
  
aView’s setRichText:true
  
aView’s useAllLigatures:true
  
aView’s setTextColor:(current application’s NSColor’s cyanColor()) –cyanColor
  
aView’s setFont:(current application’s NSFont’s fontWithName:aFontName |size|:aFontSize)
  
set aColor to current application’s NSColor’s colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.5
  
aView’s setBackgroundColor:aColor
  
aView’s setString:mesStr
  
aScroll’s setDocumentView:aView
  
aView’s enclosingScrollView()’s setHasVerticalScroller:true
  
  
— set up alert
  
set theAlert to NSAlert’s alloc()’s init()
  
tell theAlert
    its setMessageText:aMainMes
    
its setInformativeText:aSubMes
    
its addButtonWithTitle:"OK"
    
its addButtonWithTitle:"Cancel"
    
its setAccessoryView:aScroll
  end tell
  
  
— show alert in modal loop
  
NSRunningApplication’s currentApplication()’s activateWithOptions:0
  
my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
  
if (my returnCode as number) = 1001 then error number -128
end dispTextViewWithAlertdialog:

on doModal:aParam
  set (my returnCode) to aParam’s runModal()
end doModal:

–指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない)
— Original Created 2014-02-23 Shane Stanley
on getASsourceFor(anAlias as {alias, string})
  set aURL to |NSURL|’s fileURLWithPath:(POSIX path of anAlias)
  
set theScript to OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value)
  
  
if theScript is equal to missing value then
    error "Compile Error" — handle error
  else
    set sourceText to theScript’s source()
  end if
  
  
return sourceText as string
end getASsourceFor

★Click Here to Open This Script 

Posted in Color file File path Font GUI Text URL | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSAlert NSColor NSFont NSRunningApplication NSScrollView NSTextView NSURL OSAScript | Leave a comment

構文色分け情報を取得(Color Spaceを考慮)

Posted on 7月 4, 2019 by Takaaki Naganoya

macOS標準搭載のスクリプトエディタで定義している、AppleScriptの構文要素ごとの色分け情報。これを設定ファイルから取り出してレコード型データ(を入れた配列)に変換するAppleScriptの、カラースペースを考慮したデータの取り出しを行う改修版です。

AppleScriptの構文色分け情報は、ユーザーごとに異なります。一応、OSデフォルトの趣味の悪い配色なんかもありますが、

 (1)美的センスがなく見た目に気持ち悪い(ほら変更したいでしょ? 自分の好きなように変えてね、というメッセージだと受け止めました)

 (2)重複した色が設定されている構文要素がたくさんある(構文要素ごとの見分けがしにくいので、デフォルトのままだと無意味。ほら変更したくなったでしょ、というメッセージだと受け止めました)

ということから、AppleScript入門初日に設定色を変更。何度か細かい変更を行いつつも、今日までだいたい同じ感じの設定を使い続けています。

他のScripterがどのような配色にしているかはあまり知りません。Scripterごとに違うんだろうな、ぐらいの感じです。

ところが、蓋を開けてみたらこの構文色分け設定に「RGB以外の色」が設定できることが判明。けっこう長い間、この処理系使い続けてきましたけれど、昨日はじめて知りました。

具体的に言えば、RGB以外の「CMYK色」と「グレースケール色」の2つを設定可能なことが判明。CMYK色は、何度かアクセスしているうちに勝手にRGB色に置き換わってしまうようですが、グレースケールで指定した色はそのまま色種別がグレースケールのまま保持される(RGBに変換されたりしない)ようです。そのため、NSColorからredValue()などのメソッドで数値を取り出そうとするとエラーになる事例が発生したのでした。

そこで、RGBの各チャンネルの値を取り出す前にNSColorの色空間(グレースケール色空間というのはないので、種別ぐらい?)をチェックし、RGB以外であれば変換処理を行うようにしてみました。

ただし、この色空間(色モデル)の確認にNSColorのcolorSpaceNameというメソッドを使っている点に注意が必要です。これはmacOS 10.13で非推奨(deprecated)になっています。ヘッダーファイル上の説明を読むかぎりだと、Color Space(色空間)といいながら実際には色空間に該当する(HSBとかL*a*b*とか)ものを指定しているわけではないので、色タイプと言い換えることにした、という説明が行われていました。

このため、macOS 10.15betaでは未確認ではあるものの、このNSColorからRGB値を取り出すという処理自体を書き換える必要が出てくるため、本ルーチンだけ別のライブラリに分離しておくとか、メンテナンス時にわかるように書いておくとよいでしょう(NSColorのtypeを取得してみたものの、いまひとつサンプルなどもなく不明。macOS 10.14上で全部一律で0が返ってくるし)。

AppleにOS内部の機能修正リクエストを出す場合、「実際に機能不全を起こしているんだから直してほしい」と依頼してもなかなか直らない一方で、「学術的に正しくない」という指摘をされるととっとと変更するんだなーという発見をしたような気がします。

AppleScript名:構文色分け情報を取得(Color Spaceを考慮).scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/07/04
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property NSDictionary : a reference to current application’s NSDictionary
property NSUnarchiver : a reference to current application’s NSUnarchiver

set cList to getAppleScriptSourceColors() of me

–AppleScriptの構文色分けのカラー値をRGBで取得する
on getAppleScriptSourceColors()
  — get the plist info as a dictionary
  
set thePath to NSString’s stringWithString:"~/Library/Preferences/com.apple.applescript.plist"
  
set thePath to thePath’s stringByExpandingTildeInPath()
  
set theInfo to NSDictionary’s dictionaryWithContentsOfFile:thePath
  
  
— extract relevant part and loop through
  
set theArray to (theInfo’s valueForKey:"AppleScriptSourceAttributes") as list
  
  
set colList to {}
  
  
repeat with i from 1 to count of theArray
    set anEntry to item i of theArray
    
    
set colorData to NSColor of anEntry
    
set theColor to (NSUnarchiver’s unarchiveObjectWithData:colorData)
    
    
set {rVal, gVal, bVal} to retColListFromNSColor(theColor, 255) of me
    
    
set fontData to NSFont of anEntry
    
set theFont to (NSUnarchiver’s unarchiveObjectWithData:fontData)
    
    
set aFontName to theFont’s displayName() as text
    
set aFontSize to theFont’s pointSize()
    
    
set aColRec to {redValue:rVal, greenValue:gVal, blueValue:bVal, fontName:aFontName, fontSize:aFontSize}
    
    
set the end of colList to aColRec
  end repeat
  
  
return colList
end getAppleScriptSourceColors

–NSColorからRGBの値を取り出す
on retColListFromNSColor(aCol, aMAX as integer)
  set aSpace to (aCol’s colorSpaceName()) as string
  
  
if aSpace is in {"NSDeviceRGBColorSpace", "NSCalibratedRGBColorSpace"} then
    –do nothing
  else
    –RGB以外の色空間の色は、RGBに変換
    
–CMYKとグレースケールは同一メソッドでRGBに変換できることを確認済み
    
set cCol to aCol’s colorUsingColorSpaceName:"NSCalibratedRGBColorSpace"
    
if cCol = missing value then error "Color Space Conversion Error (" & aSpace & " to NSCalibratedRGBColorSpace)"
    
copy cCol to aCol
  end if
  
  
set aRed to round ((aCol’s redComponent()) * aMAX) rounding as taught in school
  
set aGreen to round ((aCol’s greenComponent()) * aMAX) rounding as taught in school
  
set aBlue to round ((aCol’s blueComponent()) * aMAX) rounding as taught in school
  
  
if aRed > aMAX then set aRed to aMAX
  
if aGreen > aMAX then set aGreen to aMAX
  
if aBlue > aMAX then set aBlue to aMAX
  
  
return {aRed, aGreen, aBlue}
end retColListFromNSColor

★Click Here to Open This Script 

Posted in Color list Record System | Tagged 10.12savvy 10.13savvy 10.14savvy NSArray NSColor NSDictionary NSString NSUnarchiver | Leave a comment

マウスカーソルを隠す→表示する

Posted on 4月 9, 2019 by Takaaki Naganoya

マウスカーソルを非表示、表示にするAppleScriptです。

マウスカーソルの変更はClassic Mac OSの時代にそういうOSAXを見かけた覚えがありますが、今日びCocoaの機能を用いて割と簡単に表示/非表示の切り替えができることに気づきました。

# カーソルのイメージを変更するのには失敗しました

長時間のバッチ(一括)処理中にユーザーに操作してほしくない場合には、デスクトップ機であればマウスを取り外しておく措置を講じたこともありますが、さらに念には念のためにこうしてマウスカーソルを非表示にしておくのもよいかもしれません。

MacBook Proなどのノートでバッチ処理を行いつつユーザーの操作により処理が妨げられることを防ぐためにカーソル非表示にするのも、(ユーザーが不安に感じなければ)案外いい手段でしょう。

AppleScript的には、意外と使い勝手がありそうです。

AppleScript名:マウスカーソルを隠す→表示する.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/04/09
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—

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

set curCursor to current application’s NSCursor’s currentCursor()

current application’s NSCursor’s hide()

delay 5

current application’s NSCursor’s unhide()

★Click Here to Open This Script 

Posted in System | Tagged 10.12savvy 10.13savvy 10.14savvy NSCursor | Leave a comment

Finderの環境設定によって得られる書類ファイル名が変わるアプリケーション

Posted on 3月 17, 2019 by Takaaki Naganoya

Apple純正のKeynote、Numbers、Pagesの動作で注意を要する動作が見られました。

macOSの各種設定については、デフォルト設定状態をなるべく変更しないで使っています(変更するのはマウス移動速度とキーボードリピート速度ぐらい?)。

Finderの環境設定についても、初期設定値からたいして変更していません。

このFinderの環境設定の中に、「すべてのファイル名拡張子を表示」という項目があります。設定するかどうかは個人の趣味によるところですが、自分はオンにしていません。デフォルトではオフなので、デフォルト値のまま使うことが多いところです。

でもまさか、オンにしておくと挙動が変わるアプリケーションが出てくるとは思ってもみませんでした。そういうのはFinder上だけの挙動だと思ってしまうところです。

AppleScript経由で得られるiWorkアプリケーションのファイル名に変化が

ご覧のとおり、Finderの設定によってiWorkアプリケーションに対してname of documentを取得したときに得られる名前が違うということを確認できました。Finderの環境設定を変更するたびにiWorkアプリケーションはいったん終了させています(起動しっぱなしだとFinderの環境設定値の変更を認識しないようなので)。

tell application "Numbers"
  set aName to name of front document
end tell

★Click Here to Open This Script 


▲Finder上の設定=「すべてのファイル名拡張子を表示」をオフ → ”name_test”


▲Finder上の設定=「すべてのファイル名拡張子を表示」をオン → ”name_test.numbers”

macOS 10.12.6、macOS 10.13.6、macOS 10.14.4Betaで挙動を確認しましたが、すべて同様の動作が確認されました。

これは、、、、、自分はよくない動作だと思いますが、まずはFinderの環境設定値「すべてのファイル名拡張子を表示」の設定内容をScriptの実行環境で統一してどちらかに設定しておく必要性を感じます。

Posted in System | Tagged 10.12savvy 10.13savvy 10.14savvy Keynote Numbers Pages | Leave a comment

Keyboard Viewerを表示する

Posted on 3月 10, 2019 by Takaaki Naganoya

入力メニューから呼び出すことのできる「キーボードビューア」(ソフトウェアキーボード)を表示するAppleScriptです。

macOSには、成り立ちのことなる2系統のソフトウェアキーボードが搭載されています。

文字入力補助用の「キーボードビューア」

1つが、本Scriptで対象にしている「キーボードビューア」。入力メニューから呼び出すタイプのソフトウェアキーボードです。昔のClassic Macintoshの時代には、ノート型のPowerBookが登場するまで(Macintosh Portableもあったものの、キーボードが取り外し可能でした)本体とキーボード、マウスが分離するタイプのコンピュータであったため、ソフトウェアキーボードの存在は必要なものでした。

キーボード未接続時の緊急用に「キー配列」というキーボードビューアの前進であるソフトウェアを使うことがありました。利用頻度ははとても低いものでした。マウスしかつなげていない時にキー入力するといった程度のものです。

昔、Classic MacOSの時代に、日本語手書きフォントでカタカナにマッピングしていたもの(R研究所の日本語手書きフォントなど)があったので、そうした変則的なフォントを入力するための補助UIとして使ったとかいう記憶はあります。

障害者補助用の「キーボード」スイッチ

もう1つが、アクセシビリティ系の機能で提供されている「キーボード」。システム環境設定>アクセシビリティ>スイッチコントロールで、「ホーム」のスイッチから、「キーボード」ボタンを選択すると表示されるソフトウェアキーボードです。

単なる文字入力だけではなく、キーボード自体が使えないユーザー向けにカーソル移動やマウスの左右クリック、ドラッグ&ドロップ、スクロールや日本語かな漢字変換などの機能を提供しています。

「キーボード」スイッチは、表示位置を変更できるものの、サイズの変更は行えませんとサイズの変更が可能です。キーボードビューアもリサイズが可能です。

昨今ソフトウェアキーボードの存在に注目が集まる

これらソフトウェアキーボード類は、タブレット型のPCでmacOSを動かしたり、Macの外部ディスプレイとしてiPadを用いる利用方法が紹介されるようになって、近年その存在が再注目されつつあります。

本AppleScriptはキーボードビューアを呼び出して表示します。呼び出しにBridgePlusを必要としており、macOS 10.14.x上で実行するためには、AppleScriptをバンドル形式のアプレットとして書き出し、アップレットのバンドル中にBrdgePlusを同梱する必要があります。

AppleScript名:Keyboard Viewerを表示する
— Created 2015-09-16 by Takaaki Naganoya
— 2015 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePLus : script "BridgePlus" version "1.2" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

property targInputID : "com.apple.KeyboardViewer"

load framework
set aList to (current application’s SMSForder’s allAvailableInputSourceIDs()) as list
if targInputID is in aList then
  set x to current application’s SMSForder’s changeInputSourceTo:targInputID
  
if x = false then error "Can not change input source."
end if

★Click Here to Open This Script 

Posted in Input Method System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy | Leave a comment

WiFiデバイスのパワーを操作

Posted on 3月 6, 2019 by Takaaki Naganoya

Macに内蔵/接続されている無線LAN(WiFi)デバイスのパワー(電源)をオン/オフ操作するAppleScriptです。

AppleScript名:WiFiデバイスのパワーを操作
— Created 2015-08-18 by Shane Stanley
— Modified 2019-03-06 by Takaaki Naganoya
use AppleScript version "2.4" –macOS 10.10 or later
use scripting additions
use framework "Foundation"
use framework "CoreWLAN"

property CWInterface : a reference to current application’s CWInterface

–Power On WiFi
set w1Res to powerControlEveryWiFiDevices(true) of me

delay 5

–Power Off WiFi
set w2Res to powerControlEveryWiFiDevices(false) of me

on powerControlEveryWiFiDevices(aFlag as boolean)
  set allNames to CWInterface’s interfaceNames()’s allObjects() as list
  
if allNames = {} then return false
  
  
set powerList to {}
  
repeat with i in allNames
    set j to contents of i
    
set aInterface to (CWInterface’s interfaceWithName:j)
    
set wRes to (aInterface’s setPower:aFlag |error|:(missing value))
    
    
–Get Power state and check it
    
set aPower to (aInterface’s powerOn()) as boolean
    
if aPower = (not aFlag) then
      if aFlag = true then
        set aStat to " on "
      else
        set aStat to " off "
      end if
      
display notification "Error occured in power" & aStat & "an Wifi deviece ( " & j & " )…."
    end if
    
set the end of powerList to aPower
  end repeat
  
  
return ({aFlag} is in powerList) –return whether some WiFi interface is on/off
end powerControlEveryWiFiDevices

★Click Here to Open This Script 

Posted in System WiFi | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy CWInterface | Leave a comment

指定Localeおよび現在のユーザー環境のLocaleから短縮曜日名を取得

Posted on 2月 16, 2019 by Takaaki Naganoya

指定の任意のLocaleもしくはScript実行中のユーザー環境のLocaleを取得して、曜日の短縮名称を取得するAppleScriptです。

AppleScript名:指定Localeおよび現在のユーザー環境のLocaleから短縮曜日名を取得
— Created 2019-02-14 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aList to getLocalizedShortDaynames("en_US")
–>  {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
set aList to getLocalizedShortDaynames("fr_FR")
–>  {"dim.", "lun.", "mar.", "mer.", "jeu.", "ven.", "sam."}
set aList to getLocalizedShortDaynames("ja_JP")
–>  {"日", "月", "火", "水", "木", "金", "土"}
set aList to getLocalizedShortDaynames("zh-Hans")
–>  {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}

–現在のユーザーのLocale情報を取得して短縮曜日名を取得
set curLoc to (current application’s NSLocale’s currentLocale’s objectForKey:(current application’s NSLocaleIdentifier)) as string
–> "ja_JP"
set bList to getLocalizedShortDaynames(curLoc) of me
–> {"日", "月", "火", "水", "木", "金", "土"}

–ローカライズされた曜日名称を返す(短縮名称)
on getLocalizedShortDaynames(aLoc)
  set df to current application’s NSDateFormatter’s alloc()’s init()
  
df’s setLocale:(current application’s NSLocale’s localeWithLocaleIdentifier:aLoc)
  
set dayNames to df’s shortStandaloneWeekdaySymbols() as list
  
return dayNames
end getLocalizedShortDaynames

★Click Here to Open This Script 

Posted in Calendar Locale System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy | Leave a comment

spacesKitで現在のSpacesのIDを取得する

Posted on 2月 12, 2019 by Takaaki Naganoya

オープンソースのTaskRail-MacをもとにしたspacesKitフレームワークを利用して、現在のSpacesのIDを取得する実験的なAppleScriptです。

–> Download spacesKit.framework (To ~/Library/Frameworks/)

Spaces変更通知を正確に受信したい

Spacesの変更操作についてはNotificationを受信できます。でも、Spacesの切り替え表示から「元と同じSpace」を選んで、Spacesの切り替えが発生しなかったとしても同様にNotificationが発生します。「現在選択中のSpaces」の情報を取得できないのでNotificationを利用しただけでは実用性がいまひとつでした。

Spacesごとに別々のDesktop Pictureを指定していればDesktop Pictureのパスをもとに特定できなくはありませんが、すべてのSpacesで同じDesktop Pictureが設定されていると区別できません。

そこで、TaskRail-Macの機能を利用して現在有効なSpacesのIDを取得し、本当に別のSpacesに切り替えたことを検出できました。

ただ、そこまでやってもいろいろ試してみると意外な伏兵に遭遇。

アプリケーションのフルスクリーン動作画面というのはOS的には動的に生成する別のテンポラリSpacesを利用しているようです。アプリケーションをフルスクリーン表示にしたり、YouTubeのムービーを全画面表示させるとSpaces切り替えNotificationを受信したりで、この「フルスクリーン表示」状態を検出・除外する方法を知りたいところです。

TaskRail-Macの返してくるSpacesのID

Spaces関連では、Terminal上から、

defaults read com.apple.spaces

と操作することで詳細な情報を取得できますが、spacesKitフレームワーク(TaskRail-Mac)で得られるIDはこのdefaltsコマンドの結果とは異なっています。

TaskRail-MacのObjective-Cのコードを読んでみると単にカウントを行なっているだけでIDに(OS内の設定値にもとづいた)根拠はないように見えます。

TaskRail-Macが返すIDは、defaults readで設定値を読み取った中に該当するものが見つかりませんでした。


▲spacesKitが返してくるID。左側のものが17207、右側デフォルトのものが311@macOS 10.14

また、複数ディスプレイを接続した環境でも、返ってくるIDは1つのみであり、メインディスプレイ以外でSpacesが変更されてもID値に変更はないため、メインディスプレイのSpacesのIDを返してくるものと考えてください。

ここで言う「メインディスプレイ」とは、MacBook系のノート型マシンの本体内蔵ディスプレイではなく、デスクトップが表示されるソフトウェア的なメインディスプレイを指します。

元になっているTaskRail-Mac自体がかなり実験的なプログラムであり、広範なハードウェアコンフィグレーション環境下でテストされたものでなく、「ディスプレイごとに個別のスペース」設定を行なっていない環境のみを考慮したものとうかがわれます。

これは、別にTaskRail-Macが悪いのではなく、AppleがSpaces関連のAPIを整備・公開していないためです。

macOS 10.14上で動かす場合には、アプレット書き出しを行なってアプレットのバンドル内にFrameworkを格納するか、~/Library/FrameworksにFrameworkをインストールしてScript Debugger上で実行、あるいはSIPを解除してスクリプトエディタ上で実行することが可能です。

AppleScript名:spacesKitで現在のSpacesのIDを取得する.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/02/09
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "spacesKit" –https://github.com/DamianSullivan/TaskRail-Mac
use scripting additions

set aSwitcher to current application’s TRDesktopSwitcher’s alloc()’s init()
set aRes to aSwitcher’s getCurrentSpaceId()

★Click Here to Open This Script 

AppleScript名:space notifier
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/25
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use framework "spacesKit" –https://github.com/DamianSullivan/TaskRail-Mac
use scripting additions

property aSwitcher : missing value
property currentSpace : 0

set aCenter to current application’s NSWorkspace’s sharedWorkspace()’s notificationCenter()

aCenter’s addObserver:me selector:"spacesChanged:" |name|:"NSWorkspaceActiveSpaceDidChangeNotification" object:(missing value)

set aSwitcher to current application’s TRDesktopSwitcher’s alloc()’s init()
set currentSpace to aSwitcher’s getCurrentSpaceId() as integer

on spacesChanged:aNotif
  set aRes to aSwitcher’s getCurrentSpaceId() as integer
  
if aRes is not equal to currentSpace then
    log aRes
    
display notification "Active Spaces changed to " & (aRes as string)
    
say "Active Spaces changed to " & (aRes as string) using "Tom"
    
set currentSpace to aRes
  end if
end spacesChanged:

★Click Here to Open This Script 

Posted in System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy | Leave a comment

スリープおよびスリープ解除Notificationを受信

Posted on 1月 27, 2019 by Takaaki Naganoya

Macがスリープ/スリープから復帰したノーティフィケーションを受信するAppleScriptです。

Cocoaの機能が利用できない時代にスリープ解除を検出するアプリケーション「Okaeri」をAppleScriptで作って動かしていましたが、あれはon idleハンドラで1秒ごとにタイマー割り込みを発生させ、前回割り込み発生時間を記録、前回割り込みと現在時刻の差分を計算し、1ないし数秒以上間隔が空いていたらスリープ解除が発生したとみなして、syslogにスリープ解除が記録されていないかをチェックするようにしていました。

なので、Cocoaの機能呼び出しやNotificationの受信を行えなくても、ある程度は同様の処理が行えるわけですが、使えれば使えたで便利ではあります。

AppleScript名:スリープおよびスリープ解除Notificationを受信.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/25
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set aCenter to current application’s NSWorkspace’s sharedWorkspace()’s notificationCenter()

aCenter’s addObserver:me selector:"notifSleep:" |name|:"NSWorkspaceWillSleepNotification" object:(missing value)

aCenter’s addObserver:me selector:"notifWaked:" |name|:"NSWorkspaceDidWakeNotification" object:(missing value)

on notifSleep:aNotif
  display notification "System will sleep"
  
say "System will sleep"
end notifSleep:

on notifWaked:aNotif
  display notification "System did wake"
  
say "System did wake"
end notifWaked:

★Click Here to Open This Script 

Posted in Noification System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSWorkspace | 2 Comments

ディスプレイのスリープ/復帰Notificationを受信

Posted on 1月 26, 2019 by Takaaki Naganoya

Macに接続・搭載しているディスプレイのスリープ/スリープ復帰が行われたノーティフィケーションを受信するAppleScriptです。

AppleScript名:ディスプレイがスリープした.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/25
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set aCenter to current application’s NSWorkspace’s sharedWorkspace()’s notificationCenter()

aCenter’s addObserver:me selector:"notifDispSleeped:" |name|:"NSWorkspaceScreensDidSleepNotification" object:(missing value)

on notifDispSleeped:aNotif
  say "Display sleeped"
end notifDispSleeped:

★Click Here to Open This Script 

AppleScript名:ディスプレイがスリープから復帰した.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/25
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set aCenter to current application’s NSWorkspace’s sharedWorkspace()’s notificationCenter()

aCenter’s addObserver:me selector:"notifDispWaked:" |name|:"NSWorkspaceScreensDidWakeNotification" object:(missing value)


on notifDispWaked:aNotif
  say "Display waked"
end notifDispWaked:

★Click Here to Open This Script 

Posted in Noification System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSWorkspace | Leave a comment

ボリウムの名称変更Notificationを受信

Posted on 1月 26, 2019 by Takaaki Naganoya

Macに接続・搭載しているドライブのボリウム名変更が行われたノーティフィケーションを受信するAppleScriptです。

ドライブ名を変更してみると、なぜか通知が2回飛んでくるところが謎です。
→ システム再起動後に追試してみましたが、通知が飛んでくるのは1回だけでした。Scriptを複数回実行してしまったのが原因だと思われます。

AppleScript名:ボリウムの名称変更_notification.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/25
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

–ドライブ名の変更時にnotify(なぜか2回通知される?)
set aCenter to current application’s NSWorkspace’s sharedWorkspace()’s notificationCenter()

aCenter’s addObserver:me selector:"driveNameChanged:" |name|:"NSWorkspaceDidRenameVolumeNotification" object:(missing value)

on driveNameChanged:aNotif
  say "Drive name changed"
end driveNameChanged:

★Click Here to Open This Script 

Posted in Noification System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSWorkspace | Leave a comment

Spaces変更Notificationを受信

Posted on 1月 26, 2019 by Takaaki Naganoya

Spacesのスペース変更が行われた(異なるスペースに変更しなくてもOK)ノーティフィケーションを受信するAppleScriptです。

ちなみに、AppleScriptによる処理を行う分にはSpacesは百害あって一利もないので、複数Spaceを登録「しないで」使うことが推奨されます。

AppleScript名:Spaces変更_notification.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/25
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set aCenter to current application’s NSWorkspace’s sharedWorkspace()’s notificationCenter()

aCenter’s addObserver:me selector:"spacesChanged:" |name|:"NSWorkspaceActiveSpaceDidChangeNotification" object:(missing value)

on spacesChanged:aNotif
  say "Active Spaces changed"
end spacesChanged:

★Click Here to Open This Script 

Posted in Noification System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSWorkspace | 1 Comment

コンピュータのシャットダウン/再起動イベントを受信

Posted on 1月 25, 2019 by Takaaki Naganoya

実行中のMacのシャットダウン/再起動イベントを受信するAppleScrptです。

Classic Mac OS時代のシステム終了項目のような処理をAppleScriptで行いたい場合に、本Scriptのような処理を常駐型アプレット形式で書き出しておいて、起動させたままにしておけば、システム終了/再起動のイベントを受信してハンドラを実行します。

スクリプトエディタ上で実行しても、イベントを受信します、一応、ねんのため。

→ Download this script archive

AppleScript名:シャットダウン_notification.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/25
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set aCenter to current application’s NSWorkspace’s sharedWorkspace()’s notificationCenter()
aCenter’s addObserver:me selector:"computerWillShutDownNotification:" |name|:"NSWorkspaceWillPowerOffNotification" object:(missing value)

on computerWillShutDownNotification:aNotif
  say "Computer Will shutdown or restart now"
end computerWillShutDownNotification:

★Click Here to Open This Script 

Posted in Noification System | Tagged 10.11savvy 10.12savvy 10.13savvy 10.14savvy NSWorkspace | Leave a comment

macOS 10.14で新設されたエラーコード-1743を確認する

Posted on 1月 16, 2019 by Takaaki Naganoya

エラーをプログラムで発生させ、macOS 10.14で新設されたエラーコード-1743のエラーメッセージを確認するAppleScriptです。

Mojaveの「オートメーション」項目未登録アプリケーションがAppleEventを他のアプリケーションに送信した場合に発生するエラー-1743。

2019-01-15 99:99:99.999999+0900 1014test[13673:1813575] *** -[AppDelegate applicationWillFinishLaunching:]: Not authorized to send Apple events to Keynote. (error -1743)

macOS 10.14以降でのみ発生するエラーであり、それ以前のバージョンのmacOSでは発生しません。

以前作った、エラーコード表をプログラムから自動で生成するAppleScriptにこの-1743のエラーを発生させ、そのエラーメッセージ内容を取得してみました。

エラー-1743のエラーメッセージのうち、「current application」の部分には任意のアプリケーション名が入るようです。

AppleScript名:error_generator
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/01/16
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.7" — Mojave (10.14) or later
use framework "Foundation"
use scripting additions

set erList to {"-1743"}

set mesList to {}

repeat with i in erList
  set j to contents of i
  
set {aNum, aMes} to errorGenerator(j) of me
  
set the end of mesList to {aNum, aMes}
end repeat

mesList
–> {{-1743, "current applicationにApple Eventsを送信する権限がありません。"}}

on errorGenerator(aNum as number)
  set handlerName to "errorGenerator"
  
try
    error number aNum
  on error errMsg number ErrNbr partial result partialResult from from_ to to_
    return {ErrNbr, errMsg}
  end try
end errorGenerator

★Click Here to Open This Script 

Posted in System | Tagged 10.14savvy | Leave a comment

Post navigation

  • Older posts
  • Newer posts

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • 開発機としてM2 Mac miniが来たのでガチレビュー
  • macOS 15, Sequoia
  • Pages本執筆中に、2つの書類モード切り替えに気がついた
  • Numbersで選択範囲のセルの前後の空白を削除
  • メキシカンハットの描画
  • Pixelmator Pro v3.6.4でAppleScriptからの操作時の挙動に違和感が
  • AppleScriptによる並列処理
  • Safariで「プロファイル」機能を使うとAppleScriptの処理に影響
  • macOS 15でも変化したText to Speech環境
  • AppleScript入門③AppleScriptを使った「自動化」とは?
  • デフォルトインストールされたフォント名を取得するAppleScript
  • macOS 15 リモートApple Eventsにバグ?
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • AppleScript入門① AppleScriptってなんだろう?
  • Script Debuggerの開発と販売が2025年に終了
  • macOS 14で変更になったOSバージョン取得APIの返り値
  • NSObjectのクラス名を取得 v2.1
  • 有害ではなくなっていたSpaces
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • Xcode上のAppleScriptObjCのプログラムから、Xcodeのログ欄へのメッセージ出力を実行

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (194) 14.0savvy (147) 15.0savvy (135) CotEditor (66) Finder (51) iTunes (19) Keynote (119) NSAlert (61) NSArray (51) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (53) NSDictionary (28) NSFileManager (23) NSFont (21) NSImage (41) NSJSONSerialization (21) NSMutableArray (63) NSMutableDictionary (22) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (119) NSURL (98) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (76) Pages (55) Safari (44) Script Editor (27) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • Beginner
  • Benchmark
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • check sum
  • Clipboard
  • Cocoa-AppleScript Applet
  • Code Sign
  • Color
  • Custom Class
  • date
  • dialog
  • diff
  • drive
  • Droplet
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Localize
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • parallel processing
  • PDF
  • Peripheral
  • process
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2025年6月
  • 2025年5月
  • 2025年4月
  • 2025年3月
  • 2025年2月
  • 2025年1月
  • 2024年12月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年6月
  • 2024年5月
  • 2024年4月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC