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

投稿者: Takaaki Naganoya

sdef(AppleScript用語辞書)に画像やムービーを入れる

Posted on 10月 25, 2019 by Takaaki Naganoya

sdef(AppleScript用語辞書)に画像が入っているとわかりやすくてよさそうだと思っていました。ただ、その実例がどこにも見つかりません。

見つからない場合には、いろいろ考えればいいわけで、少し考えて試してみたらできてしまいました。

–> Download pickup color.scptd(To ~/Library/Script Libraries)

sdefはxml形式のファイルで、その中には基本的にAppleScriptのコマンドやオブジェクト、属性値や列挙値が定義されています。

ただ、それだけだとわかりづらいかも? という配慮から、HTML形式のドキュメントも入れられるようになっています。

最近のPiyomaru Softwareのライブラリでは、sdef内にサンプルScriptを「applescript://」URL Link入りで本Blogと同様に掲載しています。これだとsdefの容量が大きくなってしまいますが、すぐに利用できる用例が掲載されていないと意味がないと判断し、ライブラリを小分けにすることでバランスを取ろうと考えました。

ここまでで、ワンクリックですぐに試せるサンプルScript入りのAppleScript用語辞書は実現できました。全コマンド、全オブジェクトの定義に対してサンプルScriptが掲載されていれば、迷うこともないでしょう。

そこまで実現しても、やはり内容を画像で伝えたい場合もあるわけで、このHTML形式のドキュメントの中にimg srcタグで画像を指し示せればいいんじゃなかろうかと思っていました。

実際、いろいろパスの書き方を工夫してみたものの、なかなか画像表示できませんでした。その一方で、リンク先が間違っているという表示にはなっているものの、画像表示自体は行えそうな雰囲気のレンダリング結果にはなっていました。

当初、バンドル内の画像を相対パスで指し示したいと試行錯誤していたものの、自分が試した範囲内ではできませんでした。Web上の画像をURLで指し示せば表示されそうな気配はしていたものの、オフライン状態で作業した場合にでも画像は表示されてほしいところです。

そんなときに、画像をbase64エンコードしてimg srcタグの中に直接記述するという荒技を見つけ、そのとおりに書いてみたところ無事表示できたという寸法です。

オフライン時に表示されなくてよいのであれば、

のように、Web上の画像をリンク表示することもできるので、sdefのサイズを大きくしたくないが画像を大量に使いたいという場合にはこちらも検討に値することでしょう。

できないと思いつつ、iframeタグでYouTubeのムービーを埋め込んでみようと試してみましたが、表示されませんでした(iframeのフレーム自体はその大きさのボックスが存在しているもよう)。mpeg4のムービーをWeb上に置いてリンクしてみたらムービー再生できました。フルスクリーン再生も可能でした。

その他、sdefのあまり利用されていない機能は、

 ・ローカライズできる

というあたりでしょうか。日本語ユーザー向けに日本語のAppleScript用語辞書も書けるわけで、けっこう英語が読めない(英語読めないとプログラミング無理だと思わなくもないですが)人が多いようなので、いろいろ試してみたいところではあります(昔、Classic MacOS時代に、e.Typistという日本語OCRソフトウェアのAppleScript用語辞書が日本語で書かれていているのを見たことがあります)。

ただ、そこにパワーを割くぐらいならサンプルScriptを掲載しておけば、くどくど説明せずともサンプルのURLリンクをクリックするだけで実際にScriptを実行できるので、めったに使わない機能ではあります。


▲FineReader OCR ProのAppleScript用語辞書が日本語ローカライズされているのを発見しました。そこ日本語化するよりも、連続OCR実行ができないとか、「C++」などの指定できない定数を定義しているあたりを修正するほうがいいと思うのですが、、、、、、

Posted in sdef | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy | 1 Comment

Music Control with AppleScript近日発売!

Posted on 10月 24, 2019 by Takaaki Naganoya

iTunesがMusic.appに置き換わったので、もともとのiTunes Controlからアップデートした、電子ブック「Music Control with AppleScript」を準備しています。

これまでの「AppleScriptえほんシリーズ」からバージョンアップして、本Blog同様に「applescript://」のURLリンクを入れているため、クリックだけですぐに内容をスクリプトエディタに転送して実行できるようになっています(OS標準搭載のPreviewではカスタムURLプロトコルのリンクがきかないので、フリーのSkimをご利用ください)。

→ PDFView上でのURLクリックのイベントをmacOS 10.15が正常にデコードしないというバグが見つかったので、そのバグに対処するための専用の簡易PDFビューワーを作成しました。macOS 10.15環境では、Skimではなくこちらを利用してください。

記事を書いている最中にこのバグに直面したので、途中でこの簡易PDFビューワーの作成の必要が生じて、若干作業が遅れております、、、、


▲テクスチャも人物も、フリー素材集を買ってきて組み合わせて使っているので、本人が描いているわけではありません

この当時には「えほんシリーズ」として位置付けていましたが、「FileMaker Pro Scripting With AppleScript」と同様、徹底活用シリーズに変更になりました。

Posted in イベント(Event) | Tagged 10.15savvy Music | Leave a comment

日付ダイアログで開始時と終了時を選択する

Posted on 10月 23, 2019 by Takaaki Naganoya

edama2さんからの投稿です。いつもながら、(同じAppleScriptを書いているのに)異種格闘技のようなフレーバーの違いを感じるものですが、ソースコードを美しく書くことへのこだわりと、実際に実現されている機能については折り紙つきです。

—- >8 投稿ここから

タイトルは「日付ダイアログで開始時と終了時を選択する」です。
「アラートダイアログ上のDate Pickerで日付選択」をベースに日付をふたつ選択できるようにしました
結果はレコードで帰って返ってきます

--> {|開始日|:date "2019年10月23日 水曜日 21:23:04", |終了日|:date "2019年10月24日 木曜日 21:23:04"}

NSDatePickerのコメントアウトしている部分を変更するとカレンダー以外にもできます

スプリクトオブジェクトの使い方が奇怪(?)だと思うかもしれませんが、
script-factory さんのクラスオブジェクトのやり方を参考に結果のプロパティ値を本体と分離するためにこうしています。

制作環境:macOS10.14.6
—– >8 投稿ここまで

まず「property parent : AppleScript」で腰を抜かしてしまいました。なるほど、こういう逃げ道があったんですか。Script文の中にCocoaの機能を呼び出すAppleScriptObjCを書く方法がなかなか見つからずに、個人的にそういう書き方はしてこなかったところですが、これは実際に試してみないと。

AppleScriptで作った部品を積み上げて新しい概念や機能を実現することには関心がありますが、記法の限界を探るという方向にはほとんど興味がないので、参考になります。

自分も、NSDatePickerにNSBoxをかぶせてアラートダイアログに表示させるところまでは同様に作っていたんですが、サイズの調整に手間取って、思い通りの表示を行えていませんでした。はい、まさにこういう形のものが作りたかった(利用したかった)ので、これを見て勉強させていただきましょう。

AppleScript名:日付ダイアログで開始時と終了時を選択する.scpt
on run
  set dateObj to my chooseDate("期間を選択", "開始日と終了日を選択してください。", "開始日", "終了日")
end run

#カレンダー作成対象の年、月を選択(ただし、日付をクリックして選択しないと値を取得できないので注意)
on chooseDate(aMainMes, aSubMes, aLabel1, aLabel2)
  script MyDialog
    property parent : AppleScript
    
use AppleScript
    
use scripting additions
    
use framework "Foundation"
    
property _the_date : missing value
    
on make
      set aClass to me
      
script
        property parent : aClass
      end script
    end make
    
## ダイアログの呼び出し
    
on chooseDate(aMainMes, aSubMes, aLabel1, aLabel2)
      set paramObj to {myMessage:aMainMes, mySubMessage:aSubMes, myLabel1:aLabel1, myLabel2:aLabel2}
      
parent’s performSelectorOnMainThread:"raize:" withObject:paramObj waitUntilDone:true
      
return (my _the_date)
    end chooseDate
    
## ダイアログの生成
    
on raize:paramObj
      set aMainMes to paramObj’s myMessage
      
set aSubMes to paramObj’s mySubMessage
      
set aLabel1 to paramObj’s myLabel1
      
set aLabel2 to paramObj’s myLabel2
      
set setTime1 to current date
      
set setTime2 to setTime1 + days
      
      
set aList to {}
      
set aList’s end to {boxLabel:aLabel1, aTime:setTime1}
      
set aList’s end to {boxLabel:aLabel2, aTime:setTime2}
      
      
set viewList to {}
      
set datePickerList to {}
      
set parentViewWidth to 0
      
set aMargin to 8
      
      
set countItem to count aList
      
repeat with num from 1 to countItem
        set anItem to (aList)’s item num
        
        
set setLabel to anItem’s boxLabel
        
set setTime to anItem’s aTime
        
        
## create a view
        
set opt to current application’s NSYearMonthDayDatePickerElementFlag
        
–set opt to opt + (current application’s NSHourMinuteSecondDatePickerElementFlag as integer)
        
tell current application’s NSDatePicker’s new()
          –setDatePickerStyle_(current application’s NSClockAndCalendarDatePickerStyle) –> 10.13以下
          
setDatePickerStyle_(current application’s NSDatePickerStyleClockAndCalendar) –> 10.14以上 カレンダー
          
–setDatePickerStyle_(current application’s NSDatePickerStyleTextField) –> 10.14以上 テキスト入力
          
–setDatePickerStyle_(current application’s NSDatePickerStyleTextFieldAndStepper) –> 10.14以上 ステップ入力
          
setDatePickerElements_(opt)
          
setDateValue_(setTime)
          
set thisSize to fittingSize()
          
setFrameSize_(thisSize)
          
          
### 余白の大きさを指定
          
set aWidth to (thisSize’s width) + aMargin * 3.75
          
set aHeight to (thisSize’s height) + aMargin * 5.25
          
set boxFrameSize to current application’s NSMakeSize(aWidth, aHeight)
          
setFrameOrigin_(current application’s NSMakePoint(aMargin, aMargin))
          
log frame()
          
set theDatePicker to it
        end tell
        
        
tell current application’s NSBox’s new()
          setTitle_(setLabel)
          
addSubview_(theDatePicker)
          
setFrameSize_(boxFrameSize)
          
setFrameOrigin_(current application’s NSMakePoint(parentViewWidth, 0))
          
set viewList’s end to it
        end tell
        
        
### 親NSViewの大きさを指定
        
set countItem2 to count viewList
        
repeat with num2 from num to countItem2
          set anItem2 to viewList’s item num2
          
set tmpFrame to anItem2’s frame()
          
set aBoxWidt to current application’s NSWidth(tmpFrame)
          
set parentViewHeight to current application’s NSHeight(tmpFrame)
          
set parentViewWidth to parentViewWidth + aMargin + aBoxWidt
          
log result
        end repeat
        
        
###
        
set datePickerList’s end to {pickerObj:theDatePicker, keyLabel:setLabel}
      end repeat
      
      
tell current application’s NSView’s new()
        –setAutoresizingMask_(0)
        
–setAutoresizesSubviews_(true)
        
setFrameSize_(current application’s NSMakeSize(parentViewWidth, parentViewHeight))
        
setSubviews_(viewList)
        
set theView to it
      end tell
      
      
## set up alert
      
tell current application’s NSAlert’s new()
        setMessageText_(aMainMes)
        
setInformativeText_(aSubMes)
        
addButtonWithTitle_("OK")
        
addButtonWithTitle_("Cancel")
        
setAccessoryView_(theView)
        
set returnCode to runModal() — show alert in modal loop
      end tell
      
      
if returnCode = (current application’s NSAlertSecondButtonReturn) then error number -128
      
      
## retrieve date
      
set keyList to {}
      
set dateList to {}
      
repeat with anItem in datePickerList
        set keyList’s end to anItem’s keyLabel
        
set dateList’s end to (anItem’s pickerObj)’s dateValue() as date
      end repeat
      
set my _the_date to (current application’s NSDictionary’s dictionaryWithObjects:dateList forKeys:keyList) as record
      
log result
    end raize:
  end script
  
  
##
  
tell (make MyDialog)
    return chooseDate(aMainMes, aSubMes, aLabel1, aLabel2)
  end tell
end chooseDate

★Click Here to Open This Script 

Posted in Calendar dialog GUI | Tagged 10.14savvy 10.15savvy | Leave a comment

CotEditorの最前面のドキュメントの選択範囲を伏せ字に

Posted on 10月 22, 2019 by Takaaki Naganoya

CotEditorの最前面のドキュメントの選択範囲を、簡易形態素解析ルーチンeasyJparseを用いて、いい感じに伏せ字にするAppleScriptです。

–> Download makeSelectionToFuseji(Code-Signed AppleScript applet with libraries in its bundle, co-work with CotEditor)

easyJparseは日本語のコマンド解析用にでっちあげた作った超簡易形態素解析プログラムです。単語(形態素)ごとに分割しますが、品詞まではわかりません。コマンド解釈用ではあるものの、少し他の用途にも使えないかと思い、このような用途に使ってみました。

# 本Scriptは、CotEditor用のScript Pack v2.0に収録されています


▲CotEditorの選択範囲を伏せ字にする。形態素解析して単語化して、単語単位で伏せ字にするかの判断を実行

テキストエディタ上で伏せ字処理というのは、個人的によく使います。たいていは、オリジナルの文章に対して同様の分量の文章を作らなくてはならないようなケースで、文字数の感覚をつかむために使います。一種のダミーレイアウトのようなものです。

本スクリプトのような伏せ字処理については、ニーズがあるんだかないんだか不明なものですが、とりあえず掲載してみました。自分で使ってみたところ、たしかに面白いものの、実用性については未知数という印象です。

(minusList of parseSPD) に入れている語群は、どこかからか拾ってきたもののようではあるものの、すでに何か方向性を見失っているような気がしないではありません。

AppleScript名:選択範囲を伏せ字に(簡易形態素解析でそれっぽく).scptd
— Created 2018-09-26 by Takaaki Naganoya
— 2018 Piyomaru Software
use AppleScript version "2.5" — El Capitan (10.11) or later
use framework "Foundation"
use scripting additions
use jParser : script "easyJParse"

property NSArray : a reference to current application’s NSArray
property NSMutableSet : a reference to current application’s NSMutableSet
property NSSortDescriptor : a reference to current application’s NSSortDescriptor

property fuesejiChar : "□"

script parseSPD
  property pList : {}
  
property p2List : {}
  
property oneLine : {}
  
property outStr : ""
  
property minusList : {}
end script

–伏せ字化しない助詞などの単語リスト。名詞だけを残すように整備。単語(形態素)単位で照合する
set (minusList of parseSPD) to {"", " ", "ー", "あ", "で", "も", "に", "と", "の", "は", "へ", "さ", "が", "せ", "か", "た", "だ", "だっ", "ば", "つ", "な", "い", "き", "お", "ら", "る", "れ", "なっ", "それ", "これ", "あれ", "どれ", "この", "どの", "あの", "その", "まで", "こと", "もの", "いつ", "いく", "たち", "ただ", "たい", "そう", "いる", "よう", "れる", "ない", "なら", "なる", "なけれ", "から", "する", "たら", "たり", "だけ", "って", "られ", "的", "化", "いくら", "そんな", "どんな", "あんな", "者", "陰", "時", "事", "こんな", "つれ", "けど", "ああ", "ある", "あっ", "あり", "しかし", "きっと", "すっかり", "例えば", "たとえば", "さっぱり", "たとえ", "だろう", "かつ", "ところ", "まるで", "だが", "全て", "すべて", "なり", "いい", "つれ", "つけ", "ながら", "せいぜい", "そうそう", "さらに", "もっと", "まだ", "なく", "し", "を", "て", "いけ", "行く", "また", "まま", "まぁ", "『", "』", "、", "。", "。。", "……。", "【", "】", "「", "」", "(", ")", "最近", "今度", "中", "チカチカ", "グラグラ", "ふわふわ", "少し", "ついで", "より", "っぽい", "ぐらい", "何", "とき", "ため", "そっくり", "そして", "やがて", "じきに", "すぐ", "今", "次", "できる", "出来る", "いや", "そう", "おそらく", "いえ", "らしい", "とも", "ほぼ", "つい", "もう", "きっかけ", "ころ", "頃", "早々", "そこ", "どこ", "なんか", "じゃ", "くれ", "ください", "こそ", "あいつ", "だれ", "誰", "おぼしき", "らしき", "らしい", "しか", "でき", "よっ", "確か", "どう", "こう", "そう", "ああ", "くる", "ざま", "ごとく", "きれ", "はず", "さらに", "さらなる", "更なる", "など", "ごと", "とても", "たく", "いう", "とっ", "いっ", "えっ", "おっ", "ここ", "そこ", "どこ", "なかっ", "ごく", "やる", "ゆい", "ふと", "たび", "ほど", "もた", "よし", "ぜひ", "いら", "よい", "ま", "み", "む", "め", "も", "や", "けれど", "だけど", "したがっ", "すごく", "そもそも", "ほしい", "なれる", "すぎ", "もふもふ", "モフモフ", "さん", "おと", "とー", "えっと", "け", "っけ", "なん", "よ", "ね", "しっくり", "くれる", "くれた", "なぜ", "まあ", "まぁ", "ん", "なんて", "!」"}

set (pList of parseSPD) to {}
set (p2List of parseSPD) to {}
set (oneLine of parseSPD) to {}
set (outStr of parseSPD) to {}

tell application "CotEditor"
  tell front document
    –選択部分が存在しているかどうかチェック
    
set aCon to contents of selection
    
if aCon = "" then return
    
    
set (pList of parseSPD) to paragraphs of aCon
  end tell
end tell

–伏せ字にする対象単語を、助詞などを消し込むことでピックアップ
repeat with i in (pList of parseSPD)
  if length of i > 1 then
    –簡易形態素解析
    
set tempList to parseJ(i) of jParser
    
    
–簡易形態素解析したリストと助詞などのリストの差分を計算
    
set cList to clacListDiff(tempList, (minusList of parseSPD)) of me
    
    
set (oneLine of parseSPD) to {}
    
repeat with ii in tempList
      set aLen to length of ii
      
if ii is in cList then
        –伏せ字化する場合
        
set bCon to multipleChar(fuesejiChar, aLen) of me
        
      else
        –そのまま出力する場合
        
set bCon to contents of ii
      end if
      
set the end of (oneLine of parseSPD) to bCon
    end repeat
    
    
–1つの文章ぶんの単語を連結
    
set cStr to retDelimedText((oneLine of parseSPD), "") of me
  else
    set cStr to ""
  end if
  
  
set the end of (p2List of parseSPD) to cStr
  
end repeat

–すべての文章を連結して配列からテキストに
set (outStr of parseSPD) to retDelimedText((p2List of parseSPD), return) of me

tell application "CotEditor"
  tell front document
    set contents of selection to (outStr of parseSPD)
  end tell
end tell

–指定文字を指定回数繰り返して連結して出力
on multipleChar(aChar as string, aLen as integer)
  set aList to {}
  
repeat aLen times
    set the end of aList to aChar
  end repeat
  
  
return retDelimedText(aList, "") of me
end multipleChar

–1D Listを要素間に指定デリミタをはさんで文字列化
on retDelimedText(aList as list, aDelim as string)
  set aText to ""
  
set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to aDelim
  
set aText to aList as text
  
set AppleScript’s text item delimiters to curDelim
  
return aText
end retDelimedText

–2つの1D Listの差分を計算
on clacListDiff(aList as list, bList as list)
  set aSet to NSMutableSet’s setWithArray:aList
  
set bSet to NSMutableSet’s setWithArray:bList
  
  
aSet’s minusSet:bSet –補集合
  
set aRes to aSet’s allObjects() as list
  
  
return aRes
end clacListDiff

★Click Here to Open This Script 

Posted in list Natural Language Processing Text | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy CotEditor NSArray NSMutableSet NSSortDescriptor | 1 Comment

Script Geek 2.0が公開される

Posted on 10月 22, 2019 by Takaaki Naganoya

Shane Stanleyのフリーソフトウェア「Script Geek」の新バージョンv2.0が公開されました。

→ Script Geek 2.0ダウンロードページ


▲Dark ModeにするとAbout画面の文字が見えない。うん、これ自分も気をつけよう(^ー^;

前バージョンからの相違点は、Dark Modeへの対応などですが、大幅に変わったりはしていません。2つのAppleScriptの処理時間を計測するというものです。

本ツールは利用頻度も高く、実際にScriptを書いている最中によく走らせています。

Cocoaの機能を呼び出す場合には、処理対象のデータ数によっては従来のAppleScriptによる処理よりも遅くなることがあるので、「本当にCocoaで処理させたほうが高速か?」ということをいちいち確認しておく必要があります。

ほんの数個の要素からなる配列のソートにCocoaの機能を使うと逆に遅くなりますし、数万要素の配列からの条件抽出にCocoaの機能を使わないと損です。

つまり、AppleScriptからのCocoaの利用については、速度的なメリットがない場合には使わないほうがいいという点が「真髄」といいますか、その一番大事なところであって、本ツールの存在・利用そのものがShane Stanleyのノウハウそのものなんですね。

ついでに、身の回りのマシンで同じ処理のベンチマークをScript Geek 2.0を用いて行ないました。処理内容は、おおよそCocoaの機能を使わないほうが速そうな、小さなデータの判定処理です。

Machine MacBookPro10,1 MacBookPro9,1 MacBookAir4,1 Macmini7,1
メインマシン。10.14以上に上げない環境 Beta版OS専用 持ち歩き用。検証環境 検証環境
CPU Core i7 2.6GHz Core i7 2.7GHz Core i5 1.6GHz Core i5 2.6GHz
CPU Core 4.0 4.0 2.0 2.0
RAM 8GB 8GB 4GB 16GB
OS 10.14.6 10.15.1beta 10.13.6 10.15
Storage SSD HDD SSD Fusion Drive
1st Script 0.115 0.138 0.182 0.086
2nd Script 0.608 14.179 1.589 13.798

以前に、花文字作成Scriptでメイン環境のMacBook Pro Retina 2012が、最近加入した検証用マシンMac mini 2014の10倍以上高速だったことがあって、しかもデータ的にはメモリ上で十分に終わってしまいそうな内容であったために、その理由がわからないままでした。

そこで、こうして手元のマシンをすべてかき集めて、Script Geekでベンチマークを行なった次第です。

その結果、

 (1)HDD搭載マシンがSSD搭載マシンの10倍程度の処理時間になっている。メモリ搭載量とか関係なくHDD搭載機だと遅い。Fusion Driveでも同様
 (2)コア数は少ないよりも多いほうがよいが、デュアルコア程度だとCocoaの機能を利用するのに不利。最低でもクアッドコアは必要
 (3)メモリは少ないよりも多いほうがよいが、それよりもブートドライブがSSDであること、CPUコア数が4コア以上であることが重要

といったことがわかりました。SSD搭載機でないマシンというのは現行のラインナップの中にも少なくなっていますが、HDD搭載のMac miniというのはプログラムの実行専用の機械としては割とありふれていますし、Fusion Drive搭載のiMacも同様でしょう。これらHDD搭載機だと場合によってはかるーく10倍ぐらい遅くなるということに留意すべきでしょう。

もちろん、ファイルI/Oを多用するScriptについてはSSDや、場合によってはRAM Diskを使うことが望ましいわけで、これぐらい処理データが小さいプログラムでも顕著な差が見られたことがポイントです。

AppleScriptで実際の処理を行なってみると、最新のマシンだからといって速くなっていないというか、むしろそんなに速くないとか、最上位機種のはずのiMac Proでも処理内容によっては2012年のMacBook Proの方が高速だったりと(これにはおどろいた)、機械ごとに得手・不得手があるというか、性能差というものが値段や年式に単純に比例しているわけではないことを痛感するものです(2013年以降、2018年ぐらいまでIntel CPUの製造プロセスは変わってないし、2018年ぐらいまでIPCが大幅に改善されたという話も聞きません)。

開発機としてしばらくMacBook Pro 13インチの2017年モデルを使っていましたが、正直MacBook Pro Retina 2012と比べてCPU自体の処理性能は同じか、むしろ遅いぐらいでした(バッテリーはアホみたいにもちましたが)。

ただ、メインメモリ8GBだとAdobeのCreative Cloudアプリケーションで足切りが行われており(最低16GB、実用上は32GBあたり?)、そろそろメイン環境は交代したいところです。

AppleScript名:script1
set aStr to "1111"
set aRes1 to chkEachDigitIsNotSameChar(aStr as string) of me
–> false

set aStr to "1234"
set aRes1 to chkEachDigitIsNotSameChar(aStr as string) of me
–> true

on chkEachDigitIsNotSameChar(aStr as string)
  set aLen to length of aStr
  
set aList to characters of aStr
  
  
set bList to {}
  
repeat with i in aList
    set j to contents of i
    
if j is not in bList then
      set the end of bList to j
    else
      return false
    end if
  end repeat
  
return true
end chkEachDigitIsNotSameChar

★Click Here to Open This Script 

AppleScript名:script2
— Created 2017-12-17 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aStr to "1111"
set aRes1 to chkEachDigitIsNotSameChar(aStr as string) of me
–> false

set aStr to "1234"
set aRes1 to chkEachDigitIsNotSameChar(aStr as string) of me
–> true

on chkEachDigitIsNotSameChar(aStr as string)
  set aList to characters of aStr
  
set aLen to length of aList
  
  
set aSet to current application’s NSCountedSet’s alloc()’s initWithArray:aList
  
set bList to (aSet’s allObjects()) as list
  
set bLen to length of bList
  
  
return (aLen = bLen)
end chkEachDigitIsNotSameChar

★Click Here to Open This Script 

Posted in Tools | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy Script Geek | Leave a comment

display text fields script Library v1.1

Posted on 10月 21, 2019 by Takaaki Naganoya

ちょっとしたデータをText Fieldの組み合わせでアラートダイアログ上に表示するUser Interfaceを提供するAppleScriptライブラリです。

–> Download displayTextFields_v11.scptd (To ~/Library/Script Libraries/)

本ライブラリは、あまり考えずにデータ内容を表示してユーザーへの確認を行うことが目的でした。実際に使ってみると、フィールド内容を微修正するような用途にも使いたいというニーズがPiyomaru Software内で出てきました。

従来の「display text fields」は単なる表示用(フィールド内容編集不可)、新規追加した「confirm text fields」コマンドではダイアログに表示したデータのユーザーによる編集が可能で、編集したデータ内容をリストで返します(キャンセルボタンのクリック時にはfalseが返る)。データの表示と微修正に便利だと思います。

もちろん、Piyomaru Software製のScript Libraryの共通仕様でAppleScript用語辞書そのものにサンプルAppleScriptを収録しているため、すぐに動かせます。

ただ、コマンドの説明文がグダグダで、いまいち英語の内容として意味が取りにくいような、、、、

AppleScript名:sample script2
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/10/05
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use tfLib : script "display text fields"

set vRes1 to (confirm text fields main message "Zip archive Result" sub message "Edit this data to proc." key list {"scpt", "scptd", "applescript"} value list {98, 16, 3})
–> {"980", "160", "30"}

★Click Here to Open This Script 

Posted in dialog GUI Script Libraries | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy | Leave a comment

CotEditor PowerPackでボツにしたScript

Posted on 10月 21, 2019 by Takaaki Naganoya

ぴよまるソフトウェアの宣伝のために配布しているCotEditor PowerPackですが、アプリケーションに現代のAppleScriptのパワーを足すとヤバいことがいろいろできるという実例になっています。

ただし、「アプリケーション内蔵メニューから呼び出す」Scriptにはセキュリティ上の制約やアプリケーション側のポリシーによる制約が大きく、いろいろボツにしたものがあります。

一部のライブラリは呼べない

一応、CotEditor内蔵のScript Menuからバンドル形式のScriptは呼べるのものの、Script Libraryを入れて呼ぶようなことはできません。そのため、Windowの回転Scriptなどはライブラリの三角関数を呼び出していたため、その部分だけ切り出してScript内からサブルーチンとして呼び出せるようにしておきました。地図表示のScript(ぴよまるソフトウェアの最寄駅表示)も、本来はchoose locationライブラリを用いていたものを、ライブラリ化しないでScript内に展開(内容をコピペ)しました。

外部Frameworkを呼び出すものは呼べない

アプレット形式(.app)のScriptの呼び出しが許可されていない(CotEditor側のポリシーの問題)ため、サードパーティのプログラムをCocoa Frameworkとしてビルドした外部Frameworkをバンドル内に入れて呼び出すことができません。この制約は割ときつくて、たいへんよく利用するBridgePlus Script LibraryのようにFrameworkをバンドル内に含むライブラリも呼べません。そのため、BridgePlusに依存している処理をAppleScriptのみで処理できるルーチンに差し替えたりしました(2次元配列のソートなど)。

辞書.appの辞書で慣用句をキーワード検索するなどのScriptや、HTMLを解析してデータを取り出すScriptは強力で役に立つのですが、Applet(.app)形式のScriptの実行が許可されないかぎりCotEditorのScript Menuからは呼べません。

Safari上の表オブジェクトをCSV化してCotEditor上に展開するScriptなどはたいへん実用性もあり、いいと思うものの、HTMLReader.frameworkなしには実現できないので、ボツになりました(個人的には使っています)。

ただし、Frameworkを含んだAppletも、OS標準装備のScript Menu側からは呼べるので、別途そういうものを企画してみてもよいのかもしれません。

REST APIを呼び出すものは配布しにくい

これは、技術的な問題ではなく運用上の問題なのですが……REST APIを呼び出すようなものは収録を見送りました。たいていのREST APIは呼び出し用のキーが必要なわけですが、それをどーやって各ユーザーに取得してもらって、かつプログラムの中に記入してもらうかなど、説明し切れない(もうちょっとスマートに利用できないと説明がつらい)と判断して割愛しました。

文字コード関連のものはボツ

文字コードがらみのものは難しいものがあります。1つは、選択中の文字列の16進ダンプScript。UnicodeのNormalizeの方式の違いにより㍿などの文字のデータの持ちかたが変わってくるので、個人的にはたまに使っていますが、CotEditorの文字コードまわりの命令が動いていないので(GUI側からは機能している)そのあたりをつつきたくなかったということはあります。あと、闇が深そうですし。

仕様を決めにくいものはボツ

「こういうのがあったらデモとしても面白い」と、思ったものはいくつかありましたが、技術的に可能であっても、仕様を決めにくいものや公開しにくいものについてはボツにしました。

たとえば、選択中の文字を画像化してAirDropで近隣のマシンに転送するScriptを企画してみたのですが、文字数に応じてフォントサイズを可変とするなど、いろいろ実現のためのアイデアは持っていました。とはいえ、実際に作ろうとすると「ちょっとしたデモ」の範疇を超えるぐらいの手間がかかるため、ボツにしました。

opensslで選択中のテキストを暗号化するScriptも、かなり昔から使っているものがあるので、実用性で考えるとあったほうがいいものです。ですが、実際にPiyomaru Softwareのアプリケーション内部で利用しているものなので、そのものを単体で配布することはためらわれたため、ボツにしました。

普段使っていないアプリケーション(Google ChromeとかPowerPointとか)をコントロールするものも割愛しました。作ろうと思えば作れるものの、何か問題が起きて書き換えたほうがいいという話になっても、日常的にいじくっていないと問題点が把握しにくいところです(Keynote v9.1で表オブジェクトの作成に問題があるバグとか、日常的に使っていないと見つかりません)。

Posted in Release | Tagged CotEditor | Leave a comment

choose date Lib

Posted on 10月 19, 2019 by Takaaki Naganoya

date pickerで日付選択ダイアログを表示するAppleScript Library「choose date Lib」です。

–> Download choose date Lib.scptd (To ~/Library/Script Libraries/)

date pickerで日付選択するScriptは割とありふれていて、難易度も低く、あえてライブラリ化する必要をそれほど感じていなかったのですが、たまに(このような部品として)使いたくなります。ライブラリ化することで、ブラックボックス化されるため大きなプログラムに突っ込んだときのシステム負荷が少ない(Script Debugger上で巨大なプログラムを編集していると応答速度が遅くなってくるので、こういうUI部品系のコードまで構文確認の対象にしたくない)、ということは確実にいえます。

外部フレームワークなしで呼び出せる部品を整備しておくとメリットが大きいため、技術的には何も見るべきものはありませんが、用意しておきました。

デフォルトの表示日時を指定できるあたりが自分的に必要な機能であり、さほどたいしたものでもありません。CotEditorのPowerPack作成時に、

「アプリケーション内蔵のスクリプトメニューから呼び出したときにウィンドウ(ダイアログ)の表示レベルがメインのアプリケーションよりも低くなる(背面に回される)」

という現象を経験していたので(CotEditor側がosascriptコマンドでScriptを呼び出していることが原因?)、Window levelについては強制的に操作しています。

本当はこれを2つ横に並べて、開始日と終了日を取得するライブラリを作りたいのですが、NSDatePickerが意外と難物で、予想外に時間がかかって放り投げてしまいました。

本ライブラリは、こんな感じ(↓)の用途に使っています。

–> Download Code-Signed AppleScript executable Applet with Library in its bundle

AppleScript名:cre & mod date modifier.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/10/19
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
use cDate : script "choose date Lib"

set aFile to choose file

tell application "Finder window"
  set aDate to creation date of aFile
end tell

set dRes1 to choose date main message "ファイルの作成&修正日変更" sub message "変更したい日付を選択してください。" default date aDate
copy dRes1 to {yNum, mNum, dNum}

set targDate to date ((yNum as string) & "/" & (mNum as string) & "/" & (dNum as string))

changeFileCreationDate(targDate, aFile) of me
changeFileModDate(targDate, aFile) of me

–指定パスのファイルの作成日時を変更する
on changeFileCreationDate(aDate, aFile)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithObject:aDate forKey:(current application’s NSFileCreationDate)
  
set aFM to current application’s NSFileManager’s defaultManager()’s setAttributes:aDic ofItemAtPath:(POSIX path of aFile) |error|:(missing value)
end changeFileCreationDate

–指定パスのファイルの修正日時を変更する
on changeFileModDate(aDate, aFile)
  set aDic to current application’s NSMutableDictionary’s dictionaryWithObject:aDate forKey:(current application’s NSFileModificationDate)
  
set aFM to current application’s NSFileManager’s defaultManager()’s setAttributes:aDic ofItemAtPath:(POSIX path of aFile) |error|:(missing value)
end changeFileModDate

★Click Here to Open This Script 

Posted in Calendar dialog Script Libraries | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy | Leave a comment

ゼロパディングのサンプルを生成してパディング桁数を選択

Posted on 10月 18, 2019 by Takaaki Naganoya

数値に対して「何桁分のゼロパディングを行うか」を選択するダイアログを表示するAppleScriptです。

数値に対して任意の桁数のゼロパディング(9–> 0009)を行うときに、桁数と実際にゼロパディングしたサンプルを生成してchoose from listによるダイアログで選択するようにしてみました。

本来であれば、ゼロパディングの桁数だけ文字入力させたり一覧から選択させるだけでよいのですが、よりわかりやすいように処理サンプルを同時に表示させています。また、サンプルは任意の範囲で乱数を表示させることで「それっぽい」「本物っぽい」雰囲気を醸し出すようにしてみました。

気分の問題なので、実用性とかそういうものを追求したものではありません。

最近は、AppleScriptもマシンの速度向上やCocoa Frameworkを利用することで高速処理が行えるようになり、何らかの処理を選択する際に「結果ごと表示して選択」するような処理を書くことが増えてきました。さすがに処理に数分かかるような処理ではそんな真似はできませんが、高速に処理できたぶんだけ使い勝手を考慮するとよいだろうかというところです。

AppleScript名:ゼロパディングのサンプルを生成.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/10/18
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

property NSMutableArray : a reference to current application’s NSMutableArray

set aList to makeSampleList(1, 8) of me
set aRes to choose from list aList with prompt "Digit Samples" with title "Zero padding digits" default items first item of aList without empty selection allowed
if aRes = false then return false
set dRes to contents of first item of aRes
set nRes to search1DList(aList, dRes) of me

on makeSampleList(aMin as integer, aMax as integer)
  set sampleList to {}
  
set aSampleMaxDigit to length of (characters of (aMax as string))
  
  
repeat with i from aMin to aMax
    set aSample to makeFN(i, aSampleMaxDigit + 1) of me
    
    
set aRand to random number from (10 ^ aMin) to (10 ^ (i – 2) – 1)
    
set aTmpStr to makeFN(aRand, i) of me
    
    
set bSample to aSample & " Sample: " & aTmpStr
    
set the end of sampleList to bSample
  end repeat
  
  
return sampleList
end makeSampleList

on makeFN(aNum as integer, aDigit as integer)
  set aText to "00000000000" & (aNum as text)
  
set aLen to length of aText
  
set aRes to text (aLen – aDigit + 1) thru -1 of aText
  
return aRes
end makeFN

on search1DList(aList, aTarg)
  set anArray to NSMutableArray’s arrayWithArray:aList
  
set anIndex to anArray’s indexOfObject:aTarg
  
if (anIndex = current application’s NSNotFound) or (anIndex > 9.99999999E+8) then –macOS 10.12.x—10.13.0はNSNotFoundの定義値が間違っているので対処
    return false
  end if
  
return (anIndex as integer) + 1 –convert index base (0 based to 1 based)
end search1DList

★Click Here to Open This Script 

Posted in dialog Number Text | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy NSMutableArray | Leave a comment

eppcによるリモートマシンの操作

Posted on 10月 16, 2019 by Takaaki Naganoya

macOS 10.15のリリースノートで書かれていたリモートAppleEventsの動作検証を行ったら、うまく動作しませんでした(!) 結局のところは、マシン名が途中で変更してあったことが原因でした。アドレス指定が正しくなかったためにマシン指定できなかった(ケアレスミス)だけだったので、これについてはOSのバグではありません。

リモートマシンへのリモートAppleEventの送信には、ネットワーク上の他のマシンを「eppc://」で指し示す必要があります。指定するマシン名はIPアドレスないしRendezvousBonjour名が使用できます。さらにここで、UID番号を指定できるのはつい最近知りました。

Classic MacOSでは、ネットワーク上の他のマシンのアプリケーションに直接命令を投げることができていましたが、Mac OS Xの途中のバージョンからアプリケーションに直接イベントを投げられなくなりました(すでに記憶があいまい)。

現在、eppcでリモートイベントを投げられるのはAppleScriptアプレットに対してのみです。それでも、ネットワークの他のマシン上のプログラムと連携する機能は重要です。

ことに、リモートAppleEventは異なるバージョンのOS間でもやりとりできるので、古いOSでしか動作しないソフトウェアを別マシンで動かしておいて、最新バージョンのOS上のAppleScriptからリモートで機能を呼び出すといった運用が可能ですし、Parallelsなどの仮想環境で動いているmacOSのマシンに対してもリモートAppleEventでやりとりできます。

AppleScript名:eppc
set myUserName to "myuser"
set myPassword to "mypass"
set myUID to "myuid"
set targMachineName to "YasMBP.local" –Bonjour名

set machineName to "eppc://" & myUserName & ":" & myPassword & "@" & targMachineName & "/?uid=" & myUID

using terms from application "testApplet"
  tell application "testApplet" of machine machineName
    set aRes to testMe("ABCDEFG")
  end tell
end using terms from
return aRes
–> "GFEDCBA"

★Click Here to Open This Script 

Posted in Remote Control | Tagged 10.15savvy | Leave a comment

シーケンシャル値の1D Listを作成してシャッフル

Posted on 10月 15, 2019 by Takaaki Naganoya

開始値から終了値までのシーケンシャルな値の入った1次元配列(1D List)を作成し、シャッフルするAppleScriptです。

もともとは、Shane Stanleyによる乱数シャッフルルーチンがあり、これにシーケンシャル値の作成部分を追加。最終的にはこのシャッフルした値をもとに文字列の入ったリストのシャッフルを行いました。そのための部品です。

# 結局、本ルーチンは不要だったので、そのままそっくり書き捨てになりました。文字列リストのシャッフルに、インデックスをシャッフルしないでも、処理対象データそのものをシャッフルさせればよかったので、不要ということに、、、、

途中まではCocoaの機能を用いて連番リストを作りかけていたのですが、自分の考えた範囲ではCocoaの機能を用いてメリットが生まれるような要素数(数万以上)のデータ処理を行う可能性が低そうだったので、連番生成はループで行っています。

AppleScript名:シーケンシャル値の1D Listを作成してシャッフル.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/10/15
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.5"
use framework "Foundation"
use framework "GameplayKit" — requires macOS 10.12
use scripting additions

set sList to makeShuffledSequantialNumList(1, 2014) of me
–> {1949, 1356, 376, 1222, 1089, 550, …..}

on makeShuffledSequantialNumList(fromNum, toNum)
  script spdL
    property nList : {}
  end script
  
  
set (nList of spdL) to {}
  
  
repeat with i from fromNum to toNum by 1
    set the end of (nList of spdL) to i
  end repeat
  
  
set anArray to current application’s NSArray’s arrayWithArray:(nList of spdL)
  
set newArray to anArray’s shuffledArray() as list — requires macOS 10.12
  
  
return newArray
end makeShuffledSequantialNumList

★Click Here to Open This Script 

Posted in list | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy NSArray | Leave a comment

CotEditorの表示用フォント名を環境設定から取得する

Posted on 10月 15, 2019 by Takaaki Naganoya

CotEditorの環境設定値(plist)から表示用フォント名を取得するAppleScriptです。

本来であれば、CotEditorのwindowオブジェクト自体に属性値として表示用フォント名がついているのが(GUI側からWindowごとに表示フォントを指定できるので)理想的ですが、そういう機能は実装されていないので、無理やりplistから読み取ってみました。

CotEditorの表示用フォントは、環境設定で指定したものがデフォルトで用いられ、個別のウィンドウごとに任意のフォントを指定できるようになっています。本Scriptで取得できるのは、個別のウィンドウの設定値ではなく、環境設定値のほうです。

defaultsコマンドでplistを読むのはあまりおすすめできない方法ですが、できないよりはマシというところです。

まっさらな(macOSをインストールしたての)環境にCotEditorをインストールして一度も環境設定でフォントを指定していない環境だとエラーになる(項目が存在しない)ので、その場合に備えてエラートラップを仕掛けています。


▲環境設定から表示フォント名を取得して、各行をプロポーショナルフォント使用時の画面描画幅をもとにソートする処理を書いたときに利用

AppleScript名:CotEditorの表示用フォント名を環境設定から取得する
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/10/15
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set fName to getCotEditorFontName() of me
–> "HiraginoSans-W3"

–CotEditorのplistから表示用のフォント設定(PostScript名)を取得する
on getCotEditorFontName()
  try
    set fnRes to do shell script "defaults read com.coteditor.CotEditor | grep fontName"
  on error
    return "" –インストール後に表示フォントの環境設定を一度も行っていないときにはエラーになる
  end try
  
set fName to extractStrFromTo(fnRes, "= \"", "\";") of me
  
return fName
end getCotEditorFontName

–指定文字と終了文字に囲まれた内容を抽出
on extractStrFromTo(aParamStr, fromStr, toStr)
  set theScanner to current application’s NSScanner’s scannerWithString:aParamStr
  
set anArray to current application’s NSMutableArray’s array()
  
  
repeat until (theScanner’s isAtEnd as boolean)
    set {theResult, theKey} to theScanner’s scanUpToString:fromStr intoString:(reference)
    
theScanner’s scanString:fromStr intoString:(missing value)
    
set {theResult, theValue} to theScanner’s scanUpToString:toStr intoString:(reference)
    
if theValue is missing value then set theValue to "" –>追加
    
theScanner’s scanString:toStr intoString:(missing value)
    
anArray’s addObject:theValue
  end repeat
  
  
if anArray’s |count|() is not equal to 1 then return ""
  
  
return first item of (anArray as list)
end extractStrFromTo

★Click Here to Open This Script 

hiro さんのコメントから、defaultsコマンドのオプション追加でずいぶんと簡潔に書けるようで、書き直しておきました。

AppleScript名:CotEditorの表示用フォント名を環境設定から取得する v2
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set fName to getCotEditorFontName() of me
–> "HiraginoSans-W3"

–CotEditorのplistから表示用のフォント設定(PostScript名)を取得する
on getCotEditorFontName()
  try
    set fnRes to do shell script "defaults read com.coteditor.CotEditor fontName"
  on error
    return "" –インストール後に表示フォントの環境設定を一度も行っていないときにはエラーになる
  end try
  
return fnRes
end getCotEditorFontName

★Click Here to Open This Script 

Posted in shell script | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy CotEditor NSMutableArray NSScanner | 3 Comments

CotEditorのScript集、PowerPack & Basic Packをv1.2にアップデート

Posted on 10月 10, 2019 by Takaaki Naganoya

CotEditorの関連ScriptをまとめたScript Pack v1.2の配布を開始しました。無償、無保証、サポートなしで提供しています。CotEditor 3.8+macOS 10.14/10.15にて検証を行っています。

–> Download Page

基礎的なサンプルScriptの「Basic Pack」、強力なユーティリティScriptの「PowerPack」から構成され、今回アップデートしたのはPowerPackです。

即戦力となる強力なScript群:PowerPack

CotEditorのスクリプトメニューにインストールして使うためのScript群です。

アップデートしたものをご紹介いたします。

・選択中の文字から花文字テキストを作成

macOS 10.15で「ヒラギノ角ゴ W3」がバンドルされなくなった(ヒラギノ角ゴシック W0〜9に集約)ため、「ヒラギノ角ゴ W3」を指定していたScriptを「ヒラギノ角ゴシック」に変更しました。

・選択範囲を処理

Wikipedia検索、各種データ検出、各種データ変換、指定文字数で擬似要約 などを追加しています。

・iOSデバイスに転送

「指定範囲から電話番号を検出してiPhoneで電話をかける」「選択範囲をメモ(Notes.app)経由で転送」を収録しています。


電話発信時の「発信」ボタンはご自分でクリックしてください(AppleScriptから無理やりクリックできないこともないですが………)。

・Spotlight検索

CotEditorのテキストで選択中の文字をキーにしてSpotlight検索を実行、結果はFinderで表示します。

・Safari(Webブラウザ)から読み込み

「HTMLソースを読み込み」「本文テキストを読み込み」を追加しました。Safariでオープン中の最前面のウィンドウの内容を取得します。

・プレゼン(Keynote)資料に出力

「インデントを反映させてKeynote書類を新規作成」「選択範囲をインデントを反映させて現在のKeynote書類にスライド追加」を追加しました。CotEditor上のテキストをもとにKeynoteのプレゼンテーションを作成します。

・PDFから情報読み込み

指定のPDFから各種情報を読み込んで、CotEditorの新規ドキュメント上に情報を展開します。「指定ページの本文テキストを読み込む」「全ページの本文テキストを読み込む」「全ページのURLリンクを読み込む(http、https)」「全ページのURLリンクを読み込む(mailto)」「TOC(Table Of Contents)読み込み」を追加しました。

その他、ちょっとしたPiyomaru Softwareのおしらせ的なメニューを入れておきました。

Posted in Release Tools | Tagged 10.12savvy 10.13savvy 10.14savvy 10.15savvy CotEditor | 2 Comments

Safariで現在見えている表を抽出してCSV書き出しv3

Posted on 10月 8, 2019 by Takaaki Naganoya

Safariの最前面のウィンドウで表示中のページのうち、現在ウィンドウ内に表示中の表要素をCSV書き出ししてNumbersでオープンするAppleScriptの改良版です。HTMLのtable中にrowspan(複数セルを行方向に連結)とcolspan(複数セルを列方向に連結)の属性値が指定されていた場合に対応します。

–> Download table2CSV_visibleonly_v2 (Code-Signed AppleScript applet with Framework and Library in its bundle)

各DOM ElementsのWebコンテンツ中の表示座標を取得して、絞り込みを行なっています。ただし、各DOM座標はWebブラウザのスクロールにしたがって数値が変わる(相対座標)ため、少々手こずりました。また、本Scriptでは上下スクロールのみ考慮してDOM要素の抽出を行なっており、横に長いページの横方向スクロールは考慮しておりません。

このバージョンではrowspan / colspanへの対処を追加しました。

行単位で(1次元配列ベースで)表を作っていてはとても対処できなかったので、HTMLの表と同じセル数のヌル文字が入った2次元配列を作成し、そこにX座標/Y座標を指定してセルを埋めるように処理内容を変更しました。また、rowspan/colspanの属性を見つけた場合には、結合されていた複数セルを個別の(同じ値を入れた)セルに分解しています。

本バージョンでは、1つのセル(td)でrowspanとcolspanを同時に指定しないことが処理の前提条件となっています。また、一番上の行がヘッダーの場合を想定しており、一番左の列がヘッダーになっているケースには対処しておりません。

AppleScript名:Safariで現在見えている表を抽出してCSV書き出しv3.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/09/22
–  Modified on: 2019/10/07
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "HTMLReader" –https://github.com/nolanw/HTMLReader
use aLib : script "arrayLib"

property NSUUID : a reference to current application’s NSUUID
property NSString : a reference to current application’s NSString
property HTMLDocument : a reference to current application’s HTMLDocument
property NSMutableArray : a reference to current application’s NSMutableArray
property NSJSONSerialization : a reference to current application’s NSJSONSerialization

set aTag to "table"

set indRes to getVisibleElementIndexList(aTag) of me
if indRes = false or indRes = {} then
  display notification "No Visible Table in Web browser"
  
return
end if

tell application "Safari"
  tell front document
    set aSource to source
  end tell
end tell

repeat with i in indRes
  set inList to filterATableAndPaseCells(aSource, i, aTag) of me
  
  
if inList = false or inList = {} then return
  
set aUUID to current application’s NSUUID’s UUID()’s UUIDString() as text
  
set aNewFile to ((path to desktop) as string) & aUUID & ".csv"
  
saveAsCSV(inList, aNewFile) of me
  
  
tell application "Numbers"
    activate
    
open (aNewFile as alias)
  end tell
end repeat

on filterATableAndPaseCells(aSource as string, targInd as integer, aTag as string)
  set aHTML to current application’s HTMLDocument’s documentWithString:(aSource as string)
  
  
–Table要素をリストアップ
  
set eList to (aHTML’s nodesMatchingSelector:aTag) as list
  
set aObj to contents of item (targInd + 1) of eList
  
  
–Count columns of Table Header (Count only)
  
set aTableHeader to (aObj’s nodesMatchingSelector:"tr")’s firstObject()
  
set hList to aTableHeader’s nodesMatchingSelector:"th"
  
set hStrList to {}
  
repeat with i1 in hList
    set hCellStr to i1’s textContent() as string
    
set the end of hStrList to (hCellStr)
  end repeat
  
set hLen to length of hStrList –count columns
  
  
  
–Acquire whole table body contents
  
set aTableBody to (aObj’s nodesMatchingSelector:"tbody")’s firstObject()
  
set bList to (aTableBody’s nodesMatchingSelector:"tr") as list
  
  
set rCount to (length of bList) –count rows
  
  
–行単位ループ
  
set yCount to 1
  
set attrList to make2DBlankArray(hLen, rCount) of aLib
  
  
repeat with i2 in bList
    set bb2List to {}
    
set i3 to (i2’s nodesMatchingSelector:"th") as list
    
if i3 = {} then
      set i3 to (i2’s nodesMatchingSelector:"td") as list
    end if
    
    
–カラム単位ループ
    
set xCount to 1
    
repeat with i4 in i3
      set anAttr to i4’s attributes()
      
set colAtr to (anAttr’s valueForKey:"colspan")
      
set rowAttr to (anAttr’s valueForKey:"rowspan")
      
set cellStr to i4’s textContent() as string
      
      
if colAtr is not equal to missing value then
        –colspan処理
        
set colNum to colAtr as integer
        
set attrList to xFill(xCount, yCount, attrList, cellStr, colNum) of aLib
        
      else if rowAttr is not equal to missing value then
        –rowspan処理
        
set rowNum to rowAttr as integer
        
set attrList to yFill(xCount, yCount, attrList, cellStr, rowNum) of aLib
        
      else if cellStr is not equal to "" then
        –通常処理
        
repeat with ii from xCount to hLen
          set aRes to getItemByXY(ii, yCount, attrList, "") of aLib
          
if aRes = "" then
            set attrList to setItemByXY(ii, yCount, attrList, cellStr) of aLib
            
exit repeat
          else
            set xCount to xCount + 1
          end if
        end repeat
        
      end if
      
      
set xCount to xCount + 1
    end repeat
    
    
set yCount to yCount + 1
  end repeat
  
  
return attrList
end filterATableAndPaseCells

–Safariのウィンドウ上で表示中のDOM Elementsを座標計算して返す
on getVisibleElementIndexList(aTag as string)
  tell application "Safari"
    set dCount to count every document
    
if dCount = 0 then return false
    
    
set jRes to do JavaScript "var winWidth = window.innerWidth,
winHeight = window.innerHeight,
winLeft = window.scrollX,
winTop = window.scrollY,
winBottom = winTop + winHeight,
winRight = winLeft + winWidth,
    elementsArray = document.body.getElementsByTagName(’" & aTag & "’),
    elemLen = elementsArray.length,
inView = [];
      
    var step;
    for (step = 0 ; step < elemLen ; step++) {
      var tmpElem = document.body.getElementsByTagName(’" & aTag & "’)[step];
      var bVar = tmpElem.getBoundingClientRect();
      if (bVar.top > 0 && bVar.top < winHeight) {
        inView.push(step);
      }
    }
    JSON.stringify(inView);"
in front document
    
    
set jList to parseJSONAsList(jRes) of me
    
return jList
    
  end tell
end getVisibleElementIndexList

on parseJSONAsList(jsRes as string)
  set jsonString to NSString’s stringWithString:jsRes
  
set jsonData to jsonString’s dataUsingEncoding:(current application’s NSUTF8StringEncoding)
  
set aJsonDict to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
return aJsonDict as list
end parseJSONAsList

–Save 2D List to CSV file
on saveAsCSV(aList as list, aPath)
  set crlfChar to (string id 13) & (string id 10)
  
set LF to (string id 10)
  
set wholeText to ""
  
  
repeat with i in aList
    set newLine to {}
    
    
–Sanitize (Double Quote)
    
repeat with ii in i
      set jj to ii as text
      
set kk to repChar(jj, string id 34, (string id 34) & (string id 34)) of me –Escape Double Quote
      
set the end of newLine to kk
    end repeat
    
    
–Change Delimiter
    
set aLineText to ""
    
set curDelim to AppleScript’s text item delimiters
    
set AppleScript’s text item delimiters to "\",\""
    
set aLineList to newLine as text
    
set AppleScript’s text item delimiters to curDelim
    
    
set aLineText to repChar(aLineList, return, "") of me –delete return
    
set aLineText to repChar(aLineText, LF, "") of me –delete lf
    
    
set wholeText to wholeText & "\"" & aLineText & "\"" & crlfChar –line terminator: CR+LF
  end repeat
  
  
if (aPath as string) does not end with ".csv" then
    set bPath to aPath & ".csv" as Unicode text
  else
    set bPath to aPath as Unicode text
  end if
  
  
writeToFileAsUTF8(wholeText, bPath, false) of me
  
end saveAsCSV

on writeToFileAsUTF8(this_data, target_file, append_data)
  tell current application
    try
      set the target_file to the target_file as text
      
set the open_target_file to open for access file target_file with write permission
      
if append_data is false then set eof of the open_target_file to 0
      
write this_data as «class utf8» to the open_target_file starting at eof
      
close access the open_target_file
      
return true
    on error error_message
      try
        close access file target_file
      end try
      
return error_message
    end try
  end tell
end writeToFileAsUTF8

on repChar(origText as text, targChar as text, repChar as text)
  set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to targChar
  
set tmpList to text items of origText
  
set AppleScript’s text item delimiters to repChar
  
set retText to tmpList as string
  
set AppleScript’s text item delimiters to curDelim
  
return retText
end repChar

★Click Here to Open This Script 

Posted in file JavaScript JSON list Record Text | Tagged 10.12savvy 10.13savvy 10.14savvy HTMLDocument NSJSONSerialization NSMutableArray NSString NSUUID Numbers Safari | 4 Comments

配列に添字的なデータを指定してアクセス v2

Posted on 10月 7, 2019 by Takaaki Naganoya

AppleScriptのリスト(list)型変数に対して、一般的な配列の添字的なパラメータを指定して値の設定や取得を行うAppleScriptの改良版です。

本バージョンでは、指定x,y座標から横方向(xFill)または縦方向(yFill)に指定回数連続して指定の値を代入するという処理を追加してあります。


▲本Scriptの実行結果のイメージ図

こうして見直してみると、値渡し(call by value)ではなく参照渡し(call by reference)で作ればよかったのではないかと思わされるものがあります。

添字は一般的な配列とは異なり1始まりです。添字指定が実際の配列のレンジを超えた場合にはエラーにせず、無視されます。配列に添字でアクセスできない(方法が違う)AppleScriptですが、昔からこういうルーチンを作って普通に使ってきました。

AppleScript名:配列に添字的なデータを指定してアクセス v2
— Created 2017-09-30 by Takaaki Naganoya
— Modified 2019-10-07 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aList to make2DBlankArray(3, 4) of me
set aList to setItemByXY(2, 3, aList, "@") of me
set aRes to getItemByXY(2, 3, aList, "") of me
–> {{"", "", ""}, {"", "", ""}, {"", "@", ""}, {"", "", ""}}

set aList to xFill(1, 1, aList, "$", 3) of me
set aList to yFill(3, 2, aList, "*", 4) of me

return aList
–> {{"$", "$", "$"}, {"", "", "*"}, {"", "@", "*"}, {"", "", "*"}}

on xFill(aX, aY, aList, aVal, aRepNum)
  repeat with x from aX to (aX + aRepNum – 1)
    set aList to setItemByXY(x, aY, aList, aVal) of me
  end repeat
  
return aList
end xFill

on yFill(aX, aY, aList, aVal, aRepNum)
  repeat with y from aY to (aY + aRepNum – 1)
    set aList to setItemByXY(aX, y, aList, aVal) of me
  end repeat
  
return aList
end yFill

on getItemByXY(aX, aY, aList, aBlankItem)
  try
    set aContents to contents of (item aX of item aY of aList)
  on error
    set aContents to aBlankItem
  end try
  
return aContents
end getItemByXY

on setItemByXY(aX, aY, aList, aContents)
  try
    set (item aX of item aY of aList) to aContents
  end try
  
return aList
end setItemByXY

–空白の2D Array を出力する
on make2DBlankArray(curLen, curMax)
  set outArray to {}
  
repeat curMax times
    set aList to {}
    
repeat curLen times
      set the end of aList to ""
    end repeat
    
set the end of outArray to aList
  end repeat
  
return outArray
end make2DBlankArray

★Click Here to Open This Script 

Posted in list | Tagged 10.12savvy 10.13savvy 10.14savvy | Leave a comment

AppleScriptのプログラムの実行を(プログラム的に内部から)止める

Posted on 10月 5, 2019 by Takaaki Naganoya

どこでもプログラムを止める方法についてです。

一般的には、メインのrunハンドラ(記述されていない暗黙のrunハンドラ内)でreturnコマンドを実行すると、実行を終了します。スクリプトエディタ上で実行した場合には、基本的にそういう動作です(「ハンドラの実行後に終了しない」にチェックを入れてアプレット書き出しした「Stay Open Applet」ではアプレットは終了しませんが、実行中の処理自体は止まります)。runハンドラからサブルーチン(ハンドラ)を呼び出している場合には、returnコマンドを実行するとrunハンドラ側に戻ってくるだけです。

# Cocoaの機能を使ってタイマーオブジェクト(NSTimer)を作成して定期的に処理呼び出しするように宣言するとか、ノーティフィケーション宣言してメモリ上にオブジェクトを作ってイベントを受信するとか、そういうScriptを実行した場合にはメモリ上にオブジェクトが常駐しているかぎり実行は止まりません(この場合、スクリプトエディタを終了させるとオブジェクトも消えて動作が完全停止)

以前に、AppleScriptの実行を止めるためにさまざまな方法で、「止めるためのアクション」を検出する方法について紹介したことがあります。

ただ、ユーザーの停止要求を受け付けても、その場ですぐに止められるかどうかは別問題です。止めるためにループで条件を検出(キー入力や特定フォルダ内のファイル/フォルダの存在確認)などを行い、止めるために全力を尽くしていました。

どこでも好きなタイミングで、メインループのような場所でもなく、呼び出されたサブルーチン内などで好きに止めたい、という場合の方法をまとめてみました。

簡単にいえば、エラーを起こして止めることになるわけですが、ダイアログでCancelボタンを押したのと同じ(害のない)エラーコードを指定します。

AppleScript名:abort script
repeat 10 times
  display dialog "TEST" buttons {"OK"} default button 1
  
error number -128
  
–> error "ユーザによってキャンセルされました。" number -128 from «script» to item
end repeat

★Click Here to Open This Script 

AppleScript名:abort script 2
on run
  display dialog "run"
  
sub1() of me
end run

on sub1()
  display dialog "sub1"
  
sub2() of me
end sub1

on sub2()
  display dialog "sub2"
  
error number -128 –ここで止まる
  
–> error "ユーザによってキャンセルされました。" number -128 from «script» to item
end sub2

★Click Here to Open This Script 

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

display text fields script Library

Posted on 10月 5, 2019 by Takaaki Naganoya

ちょっとしたデータをText Fieldの組み合わせでアラートダイアログ上に表示するUser Interfaceを提供するAppleScriptライブラリです。

–> displayTextFields (To ~/Library/Script Libraries/)

ラベル部、データ部の文字数から画面上の描画幅を計算して、ダイアログサイズやフィールドのサイズを動的に変更します(まだいまひとつかも)。表示するデータの量が多い場合にエラーを出すべきなのですが、そこはとくにケアしていません。

こういう地味な部品があるとデータ内容確認に便利であるものの、なぜか存在していないのでついでに作ってみました。

AppleScript sample name : sample script_eng
—
–  Created by: Takaaki Naganoya
–  Created on: 2019/10/05
—
–  Copyright © 2019 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
use tfLib : script "display text fields"

display text fields main message "Result" sub message "Files in the Zip Archive" key list {".scpt", ".scptd", ".applescript"} value list {98, 16, 3}

★Click Here to Open This Script 

Posted in dialog GUI | Tagged 10.12savvy 10.13savvy 10.14savvy | Leave a comment

CotEditorのScript集、PowerPack & Basic Packを配布開始

Posted on 10月 3, 2019 by Takaaki Naganoya

CotEditorの関連ScriptをまとめたScript Pack v1.0の配布を開始しました。無償、無保証、サポートなしで提供しています。

2019/10/04 アップデートしてv1.01になりました(外部ライブラリを参照していたScriptが1本あったので、スクリプトバンドル化して、ライブラリをバンドル内に入れるように修正しました)

→ Download Page

即戦力となる強力なScript群:PowerPack

CotEditorのスクリプトメニューにインストールして使うためのScript群です。

Piyomaru Softwareが「こういう機能がテキストエディタに標準装備されていてほしい」と思ったものを、自分でAppleScriptで実装したものです。つまり、毎日実際に使っているものです。

・カウントレポート
テキストエディタ上で日本語の文章を書くときに重要な、漢字、ひらがな、カタカナ、特殊記号、英字などの文字種別ごとの使用比率の集計を行います。読みやすい文章を心がける人には、これらのバランスはたいへん重要な情報です。

ただし、ここで表示している原稿用紙換算の枚数計算は単純な目安であり、実際に原稿用紙に文字を記入して改行や禁則処理を考慮した詳細なシミュレーションは行っていません。厳密に計算する場合には同梱の「原稿用紙枚数シミュレーション」のScriptを使用してください。

・AppleScriptとして解釈
さまざまなテキストエディタが擬似的な書式色分けの機能を提供していますが、実際に構文確認を行ったり、結果を取得するような機能を提供しているものはありません。

本Script集のScriptはほぼスクリプトエディタと同様の構文確認(短縮表記の展開、エラー検出)、実行時の結果取得などの機能を提供します。Cocoaの機能を利用するAppleScriptObjCのプログラムも実行できます。

※ 実行のためには、CotEditorの対象ドキュメントのシンタックスカラーリングを「AppleScript」に設定しておく必要があります


▲構文確認して短縮表記や省略表記の展開、インデントやスペース挿入などを実行


▲スクリプトエディタと同等の結果出力(Cocoa Objectは結果出力に出してもスクリプトエディタ同様に読めません)


▲ウィンドウを生成してユーザーの操作を受け付けることもできます。Script Menuから実行するよりもなぜか高機能

・選択範囲を処理
選択範囲に対してさまざまな処理を行います。コメント/アンコメント(コメント解除)は、あらかじめ書類のシンタックスカラーリングをプログラミング言語のものにしておく必要があります(コメント記号が言語ごとに違うので)。

・音声読み上げシミュレーション
CotEditor上のテキストを実際に読み上げた場合の読み上げ時間の計算を行います。ゆっくり読み上げた場合と、速く読み上げた場合の時間をCotEditorコンソールに出力したりします。

・選択中の文字から花文字テキストを作成
選択中のテキストの先頭の1文字から花文字テキストを作成します。

・Flower Text From Selection
選択中の英単語から花文字テキストを作成します(Courierなどの等幅フォントで表示してください)。

・原稿用紙枚数シミュレーション
テキストの400字詰め原稿用紙換算の枚数シミュレーションを行います。

・Window回転
CotEditorのウィンドウを10回3回まわします。とくに意味はありません(新しいMacを買ったときに自己満足で回してみるとか?)。書き換えできるので心ゆくまで回してみてください。
→ Demo Movie

・青空文庫
青空文庫のテキストを処理するサンプルです。数百Kバイト級の比較的大きなテキストをAppleScriptで高速処理するサンプルです。

・文字種別を指定して加工、別ドキュメントへ出力
特定の文字だけ抽出したり削除したりするAppleScriptのサンプルです。

基礎的なScript群:Basic Pack

CotEditorの基礎的なScriptingの参考となるサンプルScriptです。40本以上のScriptをジャンルごとに区分けして、難易度順に番号を振ってあります。

Posted in Release Tools | Tagged CotEditor | 1 Comment

透明ウィンドウで時計表示

Posted on 10月 2, 2019 by Takaaki Naganoya

透明のNSTextView+NSWindowで時計を表示するAppleScriptです。ありものを組み合わせて作ってみました。

テキストビュー+ボタンをつくる ScriptにTimerを組み合わせたぐらいです。macOS標準装備のスクリプトエディタ上でそのまま動きますし、Script Debugger上でも動作確認ずみです。

この手のプログラムは初心者が割と作りたくなるものの、作ってもそれほど役に立たない上に、「まあ、こんなもんか」という程度にしかなりません。初心者向けといえば初心者向けですが、記述量がそれほど少なくないのが困りものです(Xcode上でAppleScriptでCocoa-Appを書いたほうがずっと短く書けることでしょう)。

それもこれも、実際に動かしてみないとわからないことでしょう。Safariで表示中の表だけCSVに書き出すScriptなどと比べると、ものすごく面白くありません。

AppleScript名:テキストビュー+ボタンを作成(フォント指定)_+Timer
— Created 2019-10-02 by Takaaki Naganoya
— 2019 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

property NSFont : a reference to current application’s NSFont
property NSColor : a reference to current application’s NSColor
property NSTimer : a reference to current application’s NSTimer
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 NSSplitView : a reference to current application’s NSSplitView
property NSTextView : a reference to current application’s NSTextView
property NSWindowController : a reference to current application’s NSWindowController
property NSTitledWindowMask : a reference to current application’s NSTitledWindowMask
property NSFloatingWindowLevel : a reference to current application’s NSFloatingWindowLevel
property NSBackingStoreBuffered : a reference to current application’s NSBackingStoreBuffered

property windisp : false
property aView : missing value

set aFontName to "Arial-Black"
set aWidth to 350
set aHeight to 120
set aTitle to "Clock Test" –Window Title
set aButtonMSG to "OK" –Button Title

set aRes to checkExistenceOfFont(aFontName) of me
if aRes = false then
  display dialog "There is no <" & aFontName & "> font. Select another one." –No font
  
return
end if
set dispStr to ""

set paramObj to {myWidth:aWidth, myHeight:aHeight, myTitle:aTitle, myBMes:aButtonMSG, myTimeOut:180, myFontID:aFontName, myFontSize:48}
–my dispTextView:aRecObj
my performSelectorOnMainThread:"dispTextView:" withObject:paramObj waitUntilDone:true

on dispTextView:aRecObj
  set aWidth to myWidth of aRecObj as integer
  
set aHeight to myHeight of aRecObj as integer
  
set aTitle to myTitle of aRecObj as string
  
set aButtonMSG to myBMes of aRecObj as string
  
set timeOutSecs to myTimeOut of aRecObj as integer
  
set fontID to myFontID of aRecObj as string
  
set fontSize to myFontSize of aRecObj as integer
  
  
set dispStr to ""
  
  
–Make Timer
  
set aTimer to NSTimer’s scheduledTimerWithTimeInterval:1 target:me selector:"idleHandler:" userInfo:(missing value) repeats:true
  
  
— Text View Background color
  
set aColor to NSColor’s colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.0
  
set (my windisp) to true
  
  
–Text View+Scroll Viewをつくる
  
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:(NSColor’s magentaColor())
  
aView’s setFont:(NSFont’s fontWithName:fontID |size|:fontSize)
  
aView’s setBackgroundColor:aColor
  
aView’s setAlphaValue:1.0
  
aView’s setEditable:false
  
–aView’s enclosingScrollView()’s setHasVerticalScroller:true
  
  
–Buttonをつくる
  
set bButton to (NSButton’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, 40)))
  
bButton’s setTitle:aButtonMSG
  
bButton’s setTarget:me
  
bButton’s setAction:("clicked:")
  
  
–SplitViewをつくる
  
set aSplitV to NSSplitView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aHeight, aWidth))
  
aSplitV’s setVertical:false
  
  
aSplitV’s addSubview:aView
  
aSplitV’s addSubview:bButton
  
aSplitV’s setNeedsDisplay:true
  
  
–WindowとWindow Controllerをつくる
  
set aWin to makeWinWithView(aSplitV, aWidth, aHeight, aTitle, 1.0)
  
aWin’s makeKeyAndOrderFront:(missing value)
  
set wController to NSWindowController’s alloc()
  
wController’s initWithWindow:aWin
  
aWin’s makeFirstResponder:aView
  
aView’s setString:dispStr
  
wController’s showWindow:me
  
  
set aCount to timeOutSecs * 10 –timeout seconds * 10
  
repeat aCount times
    if (my windisp) = false then
      exit repeat
    end if
    
delay 0.1
    
set aCount to aCount – 1
  end repeat
  
  
aTimer’s invalidate() –Stop Timer
  
my closeWin:aWin
  
end dispTextView:

–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 –NSBorderlessWindowMask
  
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 setBackgroundColor:(NSColor’s clearColor())
  
  
aWin’s setTitle:aTitle
  
aWin’s setDelegate:me
  
aWin’s setDisplaysWhenScreenProfileChanges:true
  
aWin’s setHasShadow:true
  
aWin’s setIgnoresMouseEvents:false
  
aWin’s setLevel:(NSFloatingWindowLevel)
  
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
  aWindow’s |close|()
end closeWin:

–指定PostScript名称のフォントがコンピューター上に存在するかどうかチェック
on checkExistenceOfFont(fontName as string)
  if fontName = "" then return false
  
set aFont to NSFont’s fontWithName:fontName |size|:9.0
  
if aFont = missing value then
    return false
  else
    return true
  end if
end checkExistenceOfFont

–タイマー割り込み
on idleHandler:aSender
  set mesStr to time string of (current date)
  
aView’s setString:mesStr
end idleHandler:

★Click Here to Open This Script 

Posted in Color dialog | Tagged 10.12savvy 10.13savvy 10.14savvy NSBackingStoreBuffered NSButton NSColor NSFloatingWindowLevel NSFont NSScreen NSSplitView NSTextView NSTimer NSTitledWindowMask NSWindow NSWindowController | 6 Comments

iWork Appsがアップデート、表の新規作成時バグは未修正

Posted on 10月 2, 2019 by Takaaki Naganoya

iWork Apps(Keynote、Pages、Numbers)がアップデートし、Keynote v9.2、Pages v8.2、Numbers v6.2になりました。

KeynoteとNumbersで表の新規作成時に特定のセル数でエラーになる(ほとんどのケースでエラーになる)バグが修正されていないことを確認しました。Pagesは未確認です。

Pages v8.2で表の新規作成を試してみたところ、Pagesでは行数や桁数を指定しても問題なく作成できました。

tell application "Pages"
  tell front document
    tell page 1
      make new table at beginning with properties {row count:20, column count:5, header row count:2, header column count:2, position:{60, 80}}
    end tell
  end tell
end tell

★Click Here to Open This Script 

Numbersでimageのposition X座標による制御ができないバグはNumbers v6.2で修正されたことを確認しました。

Posted in Bug | Tagged Keynote Numbers Pages | Leave a comment

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • Numbersで選択範囲のセルの前後の空白を削除
  • macOS 15でも変化したText to Speech環境
  • AppleScript入門③AppleScriptを使った「自動化」とは?
  • Script Debuggerの開発と販売が2025年に終了
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • KagiのWebブラウザ、Orion
  • macOS 26, Tahoe
  • AppleScript入門① AppleScriptってなんだろう?
  • macOS 14で変更になったOSバージョン取得APIの返り値
  • macOS 15 リモートApple Eventsにバグ?
  • NSObjectのクラス名を取得 v2.1
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • 2024年に書いた価値あるAppleScript
  • 有害ではなくなっていたSpaces
  • Pixelmator Proがv3.6.8でHDR画像をサポート
  • Xcode上のAppleScriptObjCのプログラムから、Xcodeのログ欄へのメッセージ出力を実行
  • (確認中)AppleScript Dropletのバグっぽい動作が解消?
  • AVSpeechSynthesizerで読み上げテスト
  • AppleScript Dropletのバグっぽい動作が「復活」(macOS 15.5β)
  • 指定フォルダ以下の画像のMD5チェックサムを求めて、重複しているものをピックアップ

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (201) 14.0savvy (156) 15.0savvy (145) CotEditor (66) Finder (52) 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) Pixelmator Pro (20) 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
  • Scripting Additions
  • 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年9月
  • 2025年8月
  • 2025年7月
  • 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