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

タグ: 10.14savvy

新発売:AppleScript基礎テクニック集(13)ファイル処理

Posted on 6月 1, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第13巻、「ファイル処理」です。PDF 33ページ、サンプルAppleScriptのZipアーカイブを添付。

→ 販売ページ

AppleScriptによるファイル処理は、MacBook AirからはじまったSSD標準採用、macOS 10.10以降のCocoa Scriptingの標準化、高速なApple Siliconへの移行なども相まって、非常に高速なものとなってきました。とくに、NSFileManager経由で処理をしたときの速度がすさまじく高速です。最新のOS、最新のマシンの組み合わせで必携の一冊!

目次:

最近のmacOSのファイル処理事情

AppleScriptのファイル処理には3通り
フルディスクアクセスの設定を
64ビット化されてFinderは遅くなった
どこで差がつく? ファイル処理
複数の条件をつけてFinderでファイル取得

条件抽出

ファイル情報の抽出
Finderラベルによる抽出

リネーム(名称変更)

ファイルの名称変更=リネーム
フォルダの名称変更=リネーム

コピー(複製)

ファイルのコピー
フォルダのコピー

移動

ファイルの移動
フォルダの移動

削除

ゴミ箱への移動を行うだけの「ファイル削除」
ファイルの完全削除
ゴミ箱への移動を行うだけの「フォルダ削除」
フォルダの完全削除

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

人類史上初、魔導書の観点から書かれたAppleScript入門書「7つの宝珠」シリーズ開始?!

Posted on 5月 30, 2022 by Takaaki Naganoya

いつものようにコードレス糸電話(FaceTime Audio)で企画会議を行なっていたら、「プログラミングを魔導書の形式で書くことが可能なのではないか?」というアイデアが登場。その場でアイデアスケッチを行い、あれよあれよという間に、実物ができてしまいました。

→ 販売ページ

ノリと勢いだけで作ってしまった1冊ですが、ビジュアル要素多めでまとめられました。ただ、宗教的なアレとかナニとかを完全に無視して作ったものなので、日本国内でしか流通させないほうがよいでしょう。

本書は、プログラミングという魔法について、「魔導書」の観点から記した人類最初の書物である。

難解なプログラミングを、なじみ深い魔導書の観点から説明すると親しみやすくなるのだろうか、という1つの魔術モルモット実験でもある。

本書で扱う内容はごくごく簡単で基礎的な内容だが、このぐらいにしぼって解説すれば難しく見えないという7テーマ、七宝珠である。

「習うより慣れろ」ということわざがあるように、難解な魔術であっても苦手意識を持たずに「慣れる」ことは重要である。 本書をもってしても、真の魔道士を育成することは難しい。だが、「だいたいこんなかんじ」という感覚をつかむためには、このぐらいの分量に抑えることが肝要だろう。

PDF 31ページ

目次

■魔導書「7つの宝珠」

神(Computer)との対話を行う人の子の書
失われし魔法の7つの宝珠を求めて
変数と代入文という最初の宝珠
if文〜条件分岐という宝珠
繰り返しループ 体力を削らせない宝珠
配列変数 詠唱呪文の機能を高める宝珠
コメント文 失われた知恵の宝珠
ログ表示 簡単に変数の中身を確認する宝珠
終了 そこで呪文実行を止める宝珠

■第1の宝珠 変数と代入文

神の言葉から人の子の言葉への移行
巻物で満ち溢れる人の子の世
牛飼いを羊飼いに変える変数
変数に牛や羊を入れるのが「代入」
変数の中に何がある?

■最短詠唱呪文集

魔術入門〜最短詠唱呪文
警告音を鳴らす魔術「beep」
現在の日付を知る魔法「current date」
クリップボードの内容を調べる魔法
時間待ちを行う魔法「delay」
ゆうしゃ(=あなた)のステータス

Posted in Books news | Tagged 10.13savvy 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

新発売:AppleScript基礎テクニック集(12)Unix shell commandの利用

Posted on 5月 26, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第12巻、「Unix shell commandの利用」です。PDF 34ページ、サンプルAppleScriptのZipアーカイブを添付。

→ 販売ページ

Unix shell commandの利用といったときに、「AppleScriptからdo shell scriptコマンドでshell commandを呼び出す」話と、「shell commandやshell scriptの中でAppleScriptで書いたプログラムを呼び出す」という、まったく価値観の異なる別の話が含まれています。

本書は、これらのまったく別な話に含まれている概念やノウハウを整理し、わかりやすく具体的にその方法や制限についてご紹介する本です。

目次

■Terminal環境とdo shell script環境の違い

shell scriptをAppleScriptと組み合わせるために
ターミナルに書類のパスを入力する方法
Terminalからプロセスの確認と終了を
Terminalとdo shell sciptの環境変数
Terminal.appをAppleScriptで操作できる①
Terminal.appをAppleScriptで操作できる②

AppleScriptからshell scriptを呼び出す

do shell scriptコマンド
パス形式変換
Terminal.app上と同じ環境変数を使用するには
参考資料:新規インストールしたユーザーの環境変数
パラメータの与え方について
do shell scriptコマンドちょっといいノウハウ
コマンドライン呼び出しプログラムをScriptに同梱

shell scriptからAppleScriptを呼び出す

AppleScript関連のshell command
shell scriptからAppleScriptを呼び出す方法①
shell scriptからAppleScriptを呼び出す方法②
パラメータ指定できるAppleScriptの書き方
AppleScriptライブラリを呼び出せる?
パイプで指定した内容を受信できる?
GUI Scriptingを利用できる?
ホームディレクトリ下のFrameworkを呼べる?

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

新発売:AppleScript基礎テクニック集(11)AppleScriptアプレットとドロップレット

Posted on 5月 20, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第11巻、「AppleScriptアプレットとドロップレット」です。PDF 41ページ、サンプルAppleScriptのZipアーカイブを添付。

→ 販売ページ

本シリーズも、着手した頃には「そんなに細切れのテーマで書けるのか?」「そんな作り方で作れるはずがない」といった意見が集まっていたものですが(チーム内の打ち合わせ時には割と批判的です)、実際に作り出したらトンでもなく「書くべきこと」があって、書けば書くほど新たなテーマが見つかるという恐るべき状態。

今回の「アプレット」「ドロップレット」については、あまり振り返ったことがなかったのですが、いざ書いてみると尋常でないほどの情報が溜まっていました。

スクリプトエディタとScript Debuggerという2つの開発環境のちがい、アプレット、ドロップレット、Cocoa-AppleScriptアプレット、Script Debuggerの拡張ドロップレットなどなど。常駐タイプのアプレットに、タイマー割り込み処理のアプレット。アプレットのアイコンのカスタマイズに、アプレット内にAppleScriptライブラリを同梱する方法、Cocoa Frameworkを入れて呼び出す方法など、盛りだくさんな内容をお送りしています。

目次

■アプレット

AppleScriptをアプリケーション形式で書き出し
AppleScriptアプレットの種類
AppleScriptアプレットの作成方法
AppleScriptアプレットのオプション指定
常駐型AppleScriptアプレットの作成方法
常駐型AppleScriptアプレットの記述
アプレットの「初期画面」を指定
「初期画面」に画像をペーストした場合の動作
アプレット/ドロップレットのユーザーインタフェース
資料:スクリプト/アプレットのバンドル構造
資料:アプレットのカスタマイズ①
資料:アプレットのカスタマイズ②
資料:アプレットのカスタマイズ③

■Cocoa-AppleScriptアプレット

Cocoa-AppleScriptアプレットの作成方法
参考資料:Delegateスクリプトの内容確認方法
参考資料:Delegateスクリプトのヘッダー内容
参考資料:Delegateスクリプトのハンドラ

■Script Debuggerのアプレット/拡張アプレット

AppleScriptアプレット(SD)の作成方法
AppleScript拡張アプレット(SD)の作成方法
AppleScript拡張アプレット(SD)の作成方法

■ドロップレット

AppleScriptドロップレットの作成方法
AppleScriptドロップレットの作成方法
ドロップレットによるファイルの受信
macOS 10.12以降の問題への対策ドロップレット
macOS 12.4上でドロップレット処理を実験

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

新発売:AppleScript基礎テクニック集(10)ループ処理

Posted on 5月 13, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第10巻、「ループ処理」です。PDF 33ページ、サンプルAppleScriptのZipアーカイブを添付。

→ 販売ページ

ループ処理について、さまざまなrepeat文のバリエーションをまんべんなくすべて知って理解するよりも「間違いなく必要な場所で使える」ことが重要です。

repeat文にもいくつか書き方はあるものの、おおよそ2パターンぐらいでだいたい足ります。

それでも、複数の配列を同時にループしなくてはならないとか、ステップ値を想定の値に合わせるための調整とか、ノウハウらしきものはいろいろあります。

また、参照値をそのまま使うとエラーになる例もあるため、「contents of」でオブジェクトを取り出す必要があるといったささいなノウハウが必要なものでもあります。

目次

■ループによる繰り返し処理

AppleScriptの制御構文
繰り返しループ
repeat文①
repeat文②
repeat文③
repeat文④
repeat文⑤
repeat文⑥
exit repeat
多重ループ+exit repeat

■アプリケーションから取得したオブジェクトでループ

アプリケーションのオブジェクトを処理
Photos上の選択中の写真から情報を取得
Keynoteで選択中のオブジェクトを位置でソート
Numbersで表のセルが連結されていたら分離
targetが重複しているFinder Windowをクローズする
ミュージック.appで選択中のtrackの情報取得
大量のオブジェクト受信に備える

■高度な処理を簡潔に記述

複数の配列の同時ループ
ページ分け
再帰処理

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

Safariで表示中のYouTubeムービーのサムネイル画像を取得

Posted on 5月 9, 2022 by Takaaki Naganoya

Safariで表示中のYouTubeムービーのサムネール画像を取得、保存、表示するAppleScriptです。

YouTubeのムービーのサムネール画像の取得方法を確認し、動作確認用にダイアログ表示+画像保存の機能を追加したものです。Script Debugger上で動かしている分には、NSImageの内容を結果表示ビューワで自動表示されますが、ない人向けに付けた機能です。

画像自体は、「ピクチャ」フォルダにUUIDつきでPNG形式で保存します。

–> Download Script bundle with Library

掲載リストには、画像表示ライブラリが含まれていないため、そのままでは実行できません。上記のScript Bundleをダウンロードして実行する必要があります。

AppleScript名:Safariで表示中のYouTubeムービーのサムネイル画像を取得.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/05/09
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use imgLib : script "imageDisplayLib"

property NSUUID : a reference to current application’s NSUUID
property |NSURL| : a reference to current application’s |NSURL|
property NSString : a reference to current application’s NSString
property NSImage : a reference to current application’s NSImage
property NSPNGFileType : a reference to current application’s NSPNGFileType
property NSURLComponents : a reference to current application’s NSURLComponents
property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep
property NSMutableDictionary : a reference to current application’s NSMutableDictionary

tell application "Safari"
  tell front document
    try
      set aURL to URL
    on error
      set aURL to "https://www.youtube.com/watch?v=_fmDtIV9vvI"
    end try
  end tell
end tell

if aURL does not start with "https://www.youtube.com/watch?" then return

set urlDict to parseURLParamsAsDict(aURL) of me
set aParam to urlDict’s valueForKey:"v"
if aParam = missing value then return

set imgURL to "https://i1.ytimg.com/vi/" & (aParam as string) & "/mqdefault.jpg"
set newURL to |NSURL|’s URLWithString:imgURL
set aImg to NSImage’s alloc()’s initWithContentsOfURL:newURL

set imgPath to (POSIX path of (path to pictures folder) & ((aParam as string) & "_") & (NSUUID’s UUID()’s UUIDString()) as string) & ".png"

–Save
saveNSImageAtPathAsPNG(aImg, imgPath) of me

–Display
dispImage(aImg, "YouTube thumbnail") of imgLib

on parseURLParamsAsDict(aURL)
  set components to NSURLComponents’s alloc()’s initWithString:aURL
  
set qList to (components’s query())’s componentsSeparatedByString:"&"
  
  
set paramRec to NSMutableDictionary’s dictionary()
  
  
repeat with i in qList
    set keyAndValues to (i’s componentsSeparatedByString:"=")
    (
paramRec’s setObject:(keyAndValues’s objectAtIndex:1) forKey:(keyAndValues’s objectAtIndex:0))
  end repeat
  
  
return paramRec
end parseURLParamsAsDict

–NSImageを指定パスにPNG形式で保存
on saveNSImageAtPathAsPNG(anImage, outPath)
  set imageRep to anImage’s TIFFRepresentation()
  
set aRawimg to NSBitmapImageRep’s imageRepWithData:imageRep
  
  
set pathString to NSString’s stringWithString:outPath
  
set newPath to pathString’s stringByExpandingTildeInPath()
  
  
set myNewImageData to (aRawimg’s representationUsingType:(NSPNGFileType) |properties|:(missing value))
  
set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean
  
  
return aRes –成功ならtrue、失敗ならfalseが返る
end saveNSImageAtPathAsPNG

★Click Here to Open This Script 

Posted in Image Record Text URL | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy Safari | Leave a comment

新発売:AppleScript基礎テクニック集(9)ダイアログ表示

Posted on 5月 6, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第9巻、「ダイアログ表示」です。PDF 43ページ、サンプルScript、AppleScriptライブラリのZipアーカイブを添付。

→ 販売ページ

ダイアログ表示については、たいへん基礎的な内容でありながらも数多くの機能が盛り込まれています。サードパーティ側でさまざまなダイアログを作れるようになってきて、「みんなが思っているよりも、けっこう便利」な環境ができています。

利用するかしないかは、皆様の判断によると思いますが、実際に利用した方は割と便利で手放せなくなるようです。

目次

ダイアログ表示

標準搭載のさまざまなダイアログ表示機能
メッセージ表示系ダイアログ
メッセージ表示系ダイアログ
ファイル選択ダイアログ
フォルダ選択ダイアログ
ファイル名選択ダイアログ
多項目選択系ダイアログ
色選択ダイアログ
LAN内のリモート資源の選択
ローカルのアプリケーションの選択
リモート・アプリケーションの選択

AppleScriptライブラリを利用したダイアログ表示

AppleScriptライブラリの用語辞書の確認方法
筆者のライブラリにはサンプルScript掲載
iPhoneやiPad、MacとAirDrop通信
チェックボックス選択ダイアログを表示
日付選択ダイアログを表示
場所選択ダイアログを表示
複数ポップアップ選択ダイアログを表示
指定のRTF書類から抽出した書式を選択するダイアログ
指定の場所を異なる拡大倍率で地図表示
表形式のデータをダイアログ表示
ラベルつきテキストフィールドを表示/データ修正
指定色の一覧選択ポップアップメニューを表示
Scriptでカスタマイズ可能な複雑なダイアログ

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

新発売:AppleScript基礎テクニック集(5)〜変数、プロパティ名

Posted on 4月 20, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第5巻、「変数、プロパティ名」です。PDF 31ページ、掲載Scriptアーカイブつき。

→ 販売ページ

変数名の決め方……自分がそこで困ったり悩んだり苦しんだりしたことはないのですが、いろいろ聞いてみると意外なほど困っている様子。え、そこなの????

長い変数名、短い変数名、プロパティとグローバル変数はどこが違うの? といった聞きたいけど聞く相手がいないといった「素朴な疑問」をなるべくあぶり出して、明確になるようまとめてみました。PDF 31ページ、掲載ScriptのZipアーカイブを添付。

変数/プロパティとは?

変数ってなに?
変数に入れられるものは?
ローカル変数とグローバル変数
変数の型ってあるの?
変数の型の確認方法は?
propertyと変数の違い(1/2)
propertyと変数の違い(2/2)
暗黙のrunハンドラ
暗黙のrunハンドラ内の変数
propertyの有効範囲=スコープ
propertyの有効範囲を超える
暗黙のrunハンドラ内の変数と各ローカル変数との衝突?

変数/プロパティの名前の決め方

変数名の命名ルール
「予約語」と衝突しない命名を
「予約語」と衝突しない命名を
アプリケーションの予約語
AppleScriptの単語が何として認識されているか
かんたんな変数名/プロパティ名の付け方
変数/プロパティの運用の要点

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

新発売:AppleScript基礎テクニック集(4)〜AppleScript用語辞書の読み方

Posted on 4月 13, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第4巻、「AppleScript用語辞書の読み方」です。PDF 39ページ、掲載Scriptアーカイブつき。

→ 販売ページ

AppleScript用語辞書の読み方については、業務の一環として記述していても理解していない人も多いので、理解できると大きな力になる内容です。普段使っていないアプリケーションでも、AppleScriptが書きやすくなるはずです。

用語辞書の構成要素

AppleScript用語辞書ってなに?
AppleScript用語辞書を読む前に
AppleScript用語辞書を読むために必要なもの
AppleScript用語辞書の確認方法
参考資料:えせスクリプタブルなアプリケーション一覧
AppleScript用語辞書の表示内容
AppleScript用語辞書掲載のサンプルScript
AppleScript用語辞書の生ファイルを表示
参考資料:用語辞書の生ファイルを得る意義
AppleScript用語辞書の構成要素
えせスクリプタブルな用語辞書の具体例

用語辞書の読み方

GUIアプリケーション操作のAppleScript記述例
アプリケーションのオブジェクト構造を調べる
document
へたくそなサンプルScriptをわかりやすく清書
より高機能なツールによる用語辞書の確認

画面上の機能とAppleScript的な属性値の付け合わせ

オブジェクトのプロパティを取得して調査
オブジェクトの選択状態による結果の変化
オブジェクトのプロパティを取得して調査
複数クラスの属性を継承している場合に
オブジェクトのプロパティを変更するテスト

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

新発売:AppleScript基礎テクニック集(3)〜ファイル・パス処理

Posted on 4月 10, 2022 by Takaaki Naganoya

電子書籍の新刊を発売しました。新シリーズ「AppleScript基礎テクニック集」の第3巻、「ファイル・パス処理」です。PDF 38ページ、掲載Scriptアーカイブつき。

→ 販売ページ

本書は、まさに「基礎」中の「基礎」ともいえる「パス操作」の基礎的なサンプルを提示して段階的に紹介。最近はCocoaの機能ばかり使っているので、逆にFinderやSystem Events相手に苦労しました。

ファイル・パス処理

ファイル・パス関連オブジェクトの全体像
ファイルパス各形式の特徴や用途
ファイル・パス形式
ホームディレクトリのパスを取得
参考資料:path to で指定できるパラメータ
参考資料:path to temporary items
各種パス形式の変換
パスの組み立て
指定ファイルの親フォルダ(上位フォルダ)を求める
指定パスのファイル名だけを求める
指定パスの拡張子を求める
指定パスの拡張子だけを置換
指定フォルダの存在確認
指定フォルダに指定名称のファイルが存在するか確認
指定ファイルのリネーム(名称変更)
指定フォルダのリネーム(名称変更)
指定ファイルがパッケージかどうかを求める
指定パスからUTIを求める
指定パスがフォルダかどうかを求める
POSIX pathのチルダ(「~」)を展開
フルパスからチルダ(「~」)つきPOSIX pathを計算
特定パスのローカライズ名称を求める
特定パスが所属するドライブ名を求める

Posted in Books news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

Intel MacとApple Silicon Macの速度差〜画像処理

Posted on 1月 2, 2022 by Takaaki Naganoya

macOS 11から12に移行して、なぜかリリースが近づくにつれて細かいバグや巨大なバグが顕在化し、まだ手放しでおすすめできる状況にないのが心苦しいところですが、AppleScriptからのCocoa呼び出しについてはIntel Mac/Apple Silicon Macでも速度が向上。とくに、Apple Silicon Macでの速度向上が顕著です。

で、特定の処理(巨大なlistやrecord in list同士の検索)でM1 Mac miniがiMac Proの2.5倍ぐらい速いといったベンチマークは出しているわけですが、いかにもApple Silicon Macで処理が速そうな画像処理のベンチマークを実施してみました。

Intel Mac mini 2014が手元からなくなってしまったので、以前のメインマシンであったMacBook Pro Retina 2012(MacBookPro10,1)と比較してみました。

ベンチマーク内容は、指定の画像が空白かどうかをチェックするというものです。フルHD画像でも4K画像でも8K画像でも、1ピクセルでも白くない点があれば検出できるという処理内容。外部のGPUImage FrameworkやPhotoshopのヒストグラム処理を呼び出すよりもAppleScriptだけで処理した方が速いというものです(8K画像だとPhotoshopの方が速いかも)。


▲画像解像度の変化と処理時間の相関。グラフは数値が小さいほど高速。巨大な画像になると処理速度差が大きくなる傾向にある?

だいたい、MacBook Pro Retina 2012と比べて3〜4倍ぐらいM1 Mac miniの方が高速です。MacBook Pro Retina 2012は2017年のMacBook Pro 13インチといい勝負ぐらいの速度が出ており、古い割にはごく最近まで使えていました。

そこから3〜4倍高速ということで、M1 Mac miniはコストの割にはパワフルです。ファンレスのMacBook Air M1でも同程度の速度が出るはずです。

一方で、M1 Pro/M1 Max搭載のMacBook ProでM1機よりも大幅に高速なのかと言われると……このぐらいの静止画の処理程度だとごくわずかな差しかつかないはずです。下手をすると、速度差がないかもしれません。

→ Download blank_image_detection_benchmark.zip (including script libraries)

–> Download test Data


▲バーが短いほど高速。M1がM1 Maxの2倍高速という結果が出てしまった。M1 Max MBPは2014年のIntel Mac miniより少し速いだけのマシンという結果に。2018年のIntel Mac miniとの比較だとM1 Max MBPよりもIntel Mac miniのほうが速そう

M1、M1 Max、M1 Ultra(最上位機種)で処理時間を比較した結果。予想どおりM1がM1 MaxやM1 Ultraよりも2倍以上高速。もはや8K画像ぐらいは、大きなデータにならないというべきなのか。

AppleScript名:画像の空白判定 v4_bench_時間計測.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/01/01
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.7"
use framework "Foundation"
use framework "AppKit"
use scripting additions
use mdLib : script "Metadata Lib" version "2.0.0"
use easyTable : script "display table by list"

set aFol to choose folder

set aResList to perform search in folders {aFol} predicate string "kMDItemContentTypeTree CONTAINS %@" search arguments {"public.image"}

set aList to {}
repeat with i in aResList
  set a1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate()
  
  
set iRes to checkImageIsWhite(i) of blankImageKit of me
  
  
set b1Dat to current application’s NSDate’s timeIntervalSinceReferenceDate()
  
set c1Dat to b1Dat – a1Dat
  
  
set aName to (current application’s NSString’s stringWithString:i)’s lastPathComponent() as string
  
  
if iRes = true then
    set jRes to "White"
  else
    set jRes to "Black"
  end if
  
  
–log {aName, jRes}
  
  
set the end of aList to {aName, jRes, c1Dat}
end repeat

set fLabels to {"File name", "Result", "Estimate(Seconds)"}
set aRes to (display table by list aList main message "Blank Image check" size {800, 600} labels fLabels)
return aList

script blankImageKit
  use AppleScript version "2.7" — High Sierra (10.13) or later
  
use framework "Foundation"
  
use framework "AppKit"
  
use scripting additions
  
property parent : AppleScript
  
  
property NSData : a reference to current application’s NSData
  
property |NSURL| : a reference to current application’s |NSURL|
  
property NSColor : a reference to current application’s NSColor
  
property NSImage : a reference to current application’s NSImage
  
property NSBezierPath : a reference to current application’s NSBezierPath
  
property NSBitmapImageRep : a reference to current application’s NSBitmapImageRep
  
  
  
–Compare Original Data and
  
on checkImageIsWhite(aFile)
    set aPOSIXpath to POSIX path of aFile
    
set aURL to |NSURL|’s fileURLWithPath:(aPOSIXpath)
    
    
set aNSImage to NSImage’s alloc()’s initWithContentsOfURL:(aURL)
    
set bNSImage to NSImage’s alloc()’s initWithContentsOfURL:(aURL)
    
    
set fillColor1 to NSColor’s clearColor()
    
set blankNSImage1 to drawImageWithFilledColor(aNSImage, fillColor1) of me
    
    
set fillColor2 to makeNSColorFromRGBAval(65535, 65535, 65535, 65535, 65535) of me –white
    
set blankNSImage2 to drawImageWithFilledColor(bNSImage, fillColor2) of me
    
    
set aTiff to blankNSImage1’s TIFFRepresentation()
    
set bTiff to blankNSImage2’s TIFFRepresentation()
    
    
set chkWhite to (aTiff’s isEqualToData:bTiff) as boolean
    
    
return chkWhite
  end checkImageIsWhite
  
  
  
on getSizeOfImage(anNSImage)
    set aSize to anNSImage’s |size|()
    
set aClass to class of aSize
    
if aClass = record then
      copy aSize to theSize –To macOS 10.12.x
    else –macOS 10.13 or later
      set sizeX to (item 1 of item 2 of aSize)
      
set sizeY to (item 2 of item 2 of aSize)
      
set theSize to {width:sizeX, height:sizeY}
    end if
    
return theSize
  end getSizeOfImage
  
  
  
–指定サイズの画像を作成し、背景を指定色で塗る
  
on drawImageWithFilledColor(anImage, fillColor)
    set aSize to getSizeOfImage(anImage) of me
    
    
anImage’s lockFocus()
    
    
set theRect to {{x:0, y:0}, {width:(width of aSize), height:(height of aSize)}}
    
set theNSBezierPath to NSBezierPath’s bezierPath
    
theNSBezierPath’s appendBezierPathWithRect:theRect
    
fillColor’s |set|()
    
theNSBezierPath’s fill()
    
    
anImage’s unlockFocus()
    
    
return anImage
  end drawImageWithFilledColor
  
  
  
–aMaxValを最大値とする数値でNSColorを作成して返す
  
on makeNSColorFromRGBAval(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer, aMaxVal as integer)
    set aRedCocoa to (redValue / aMaxVal) as real
    
set aGreenCocoa to (greenValue / aMaxVal) as real
    
set aBlueCocoa to (blueValue / aMaxVal) as real
    
set aAlphaCocoa to (alphaValue / aMaxVal) as real
    
set aColor to NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa
    
return aColor
  end makeNSColorFromRGBAval
  
end script

★Click Here to Open This Script 

Posted in Image | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy NSBezierPath NSBitmapImageRep NSColor NSData NSDate NSImage NSURL | Leave a comment

NSAttributedStringにtab指定つきparagraph styleを指定

Posted on 12月 31, 2021 by Takaaki Naganoya

書式付きテキスト(NSAttributedString)にパラグラフスタイルを指定して、tab指定を行い、tab展開を行うテストです。

Keynote/Pagesなどのテキストアイテムで、中にタブを含むスタイル付きテキストだった場合に、スタイル付きテキストの幅を計算したら大きな誤差が生じていたため、タブを展開して近似するサイズを取得できないかと考え、試してみたものです。

いまひとつ、まだしっくり来ていません。

AppleScript名:Attributed Stringにparagraph styleを指定してtab指定.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/12/27
—
–  Copyright © 2021 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 aStr to "Piyomaru Software  100  200  10  20"
set anAssrStr to makeRTFfromParameters(aStr, 3.0, 16, "HelveticaNeue") of me

set aTabStops to {90, 400, 500, 600, 700}
set aStyle to makeParagraphStyle(aTabStops) of me

anAssrStr’s addAttribute:(current application’s NSParagraphStyleAttributeName) value:aStyle range:(current application’s NSMakeRange(0, (anAssrStr’s |length|())))
return anAssrStr

–Make Paragraph Style
on makeParagraphStyle(tList as list)
  set tabList to {}
  
repeat with i in tList
    set the end of tabList to (current application’s NSTextTab’s alloc()’s initWithTextAlignment:(current application’s NSTextAlignmentLeft) location:i options:(missing value))
  end repeat
  
  
set aParagraphStyle to (current application’s NSParagraphStyle’s defaultParagraphStyle())’s mutableCopy()
  
aParagraphStyle’s setTabStops:tabList
  
return aParagraphStyle
end makeParagraphStyle

–Make Attributed String
on makeRTFfromParameters(aStr as string, outlineNum as real, aFontSize as real, aFontName as string)
  set aVal1 to current application’s NSFont’s fontWithName:aFontName |size|:aFontSize
  
set aKey1 to (current application’s NSFontAttributeName)
  
set aVal2 to current application’s NSColor’s redColor()
  
set aKey2 to (current application’s NSForegroundColorAttributeName)
  
set aVal3 to 1.0
  
set akey3 to (current application’s NSKernAttributeName)
  
set aVal4 to 0
  
set akey4 to (current application’s NSUnderlineStyleAttributeName)
  
  
set keyList to {aKey1, aKey2, akey3, akey4}
  
set valList to {aVal1, aVal2, aVal3, aVal4}
  
set attrsDictionary to current application’s NSMutableDictionary’s dictionaryWithObjects:valList forKeys:keyList
  
  
set attrStr to current application’s NSMutableAttributedString’s alloc()’s initWithString:aStr attributes:attrsDictionary
  
return attrStr
end makeRTFfromParameters

★Click Here to Open This Script 

Posted in RTF | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy NSMutableParagraphStyle NSTextTab | Leave a comment

FileMaker PowerPack活用ガイドを発売!

Posted on 12月 28, 2021 by Takaaki Naganoya

既存のAppleScript対応アプリケーションから、Cocoa Scriptingの現在のパワーを利用できるようにした「PowerPack」シリーズ。

第1弾は日本国内外で多くのユーザーに支持されている「CotEditor」用PowerPack。

第2弾がさまざまなプラットフォームへの広がりを見せつつmacOSのコア機能であるAppleScriptへの対応も行っているデータベース製品「FileMaker Pro」用のPowerPack。「FileMaker PowerPack」は、このFileMaker Proの上で動くCocoa AppleScriptサンプル集です。

サンプル集としてAppleScriptが掲載されているだけなく、FileMaker Pro上でそのまま実行でき、サンプルデータをもとに実行して、その結果をFileMaker Pro上に返してきます。

一般的なAppleScriptランタイム環境と異なるFileMaker Pro上のランタイム環境においても動作するようFileMaker Pro向けのチューニングを行ってあります。

「FileMaker PowerPack」は、日本国内のFileMaker系最難関コンテスト「FM-1グランプリ」への応募作品でもあり、業務効率化部門準賞 入賞作品でもあります。

日頃、AppleScriptになじみのない開発者にもこのPowerPackを試し、実際に実行し、そして書き換えて自分のシステムで使うための使い方を詳細に解説する電子書籍「FileMaker PowerPack」活用ガイドを刊行いたしました。

→ 電子書籍販売ページ

PDF 317ページ、FileMaker PowerPackの最新版 v2.1を同梱。

さらに、期間限定おまけコンテンツ「FM-1 GP戦記」(PDF 43ページ)を添付。前代未聞の難関コンテストを勝ち残るためにチーム内で行われた詳細な議論。試作品を没にしてたどりついた、コンテスト攻略の秘策とは?! いまだからこそ明かされる、真剣かつ呑気なやりとりに全米が泣いた、総ページ数350ページを超える1作です。

Posted in PRODUCTS | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy FileMaker Pro | Leave a comment

1D Listに入っているテキストから丸つき数字を抽出して数値化し、最小のものを求める

Posted on 11月 26, 2021 by Takaaki Naganoya

1D List(1D Array)に入っているテキスト要素から、丸つき数字を抽出して数値化し、得られた数値のうち最小のものを求めるAppleScriptです。

こんな、丸つき数字のテキストが入った「表」をKeynote上に作成したときに、

項目を追加したり順番を入れ替えたりすると、セルの中に入れている丸つき数字も変更する必要があります。これが手作業でたいへんめんどくさいので、Scriptで処理できるようにサブルーチンを整備してみました。

やりたいことは割とシンプルなはずなのに、割といろいろ書かないと実現しない処理でもあります。

そして、本Scriptは置換対象のデータから丸つき数字部分を取り出して、最小のものを判別し、リナンバー時の開始値を既存のデータから推測するという処理のために作ったものです。

AppleScript名:1D Listに入っているテキストから丸つき数字を抽出して数値化し、最小のものを求める.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/11/26
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set aList to {"❹Script Editor", "②Xcode", "③ショートカット", "④Script Debugger④", "⑤SD Notary", "⑥UI Browser", "⑦Accessibility Inspector"}
set aSmallestNum to getMinimumNumFromNumberWithSign(aList) of me
–> 2

–1D Listに入っているテキストから丸つき数字を抽出して数値化し、最小のものを求める
on getMinimumNumFromNumberWithSign(aList)
  set nList to {}
  
  
repeat with i in aList
    set j to contents of i
    
–与えられたテキストのうち、丸つき数字(白)の
    
set j2 to holdNumberWithSignOnly(j) of me
    
set n2List to characters of j2 –複数の丸つき数字が入っている場合に対処
    
    
repeat with ii in n2List
      set jj to contents of ii
      
set tmpNum to decodeNumFromNumWithSign(jj) of me
      
set the end of nList to tmpNum
    end repeat
    
  end repeat
  
  
set anArray to current application’s NSArray’s arrayWithArray:nList
  
set cRes to (anArray’s valueForKeyPath:"@min.self") as integer
  
return cRes
end getMinimumNumFromNumberWithSign

–指定文字列から丸つき数字のみ抽出する
on holdNumberWithSignOnly(aStr as text)
  set aNSString to current application’s NSString’s stringWithString:aStr
  
return (aNSString’s stringByReplacingOccurrencesOfString:"[^\\U000024EA-\\U000024EA\\U00002460-\\U00002473\\U00003251-\\U000032BF\\U000024FF-\\U000024FF\\U00002776-\\U0000277F\\U000024EB-\\U000024F4\\U00002780-\\U00002789\\U0000278A-\\U00002793\\U000024F5-\\U000024FE]" withString:"" options:(current application’s NSRegularExpressionSearch) range:{0, aNSString’s |length|()}) as text
end holdNumberWithSignOnly

–丸つき数字を数値にデコードする v2
on decodeNumFromNumWithSign(aStr as string)
  set numStr1 to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
  
set numStr2 to "❶❷❸❹❺❻❼❽❾❿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴"
  
set numStr3 to "➀➁➂➃➄➅➆➇➈➉"
  
set numStr4 to "➊➋➌➍➎➏➐➑➒➓"
  
set numStr5 to "⓵⓶⓷⓸⓹⓺⓻⓼⓽⓾"
  
–set numStr6 to "⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽⑾⑿⒀⒁⒂⒃⒄⒅⒆⒇"
  
–set numStr7 to "1︎⃣2︎⃣3︎⃣4︎⃣5︎⃣8︎⃣9︎⃣"
  
–set numStr8 to "⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛"
  
  
set nList to {numStr1, numStr2, numStr3, numStr4, numStr5}
  
  
repeat with i in nList
    set numTemp to contents of i
    
if numTemp contains aStr then
      using terms from scripting additions
        set bNum to offset of aStr in numTemp
      end using terms from
      
return bNum
    end if
  end repeat
  
return false
end decodeNumFromNumWithSign

★Click Here to Open This Script 

Posted in Number Text | Tagged 10.13savvy 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

文字列から丸つき数字のみ抽出する

Posted on 11月 26, 2021 by Takaaki Naganoya

指定の文字列から丸つき数字の部分だけを抽出するAppleScriptです。

丸つき数字の文字を数値に変換するサブルーチンのために作成したものです。

AppleScript名:文字列から丸つき数字のみ抽出する.scpt
–  Original by: Shane Stanley
–  Created on: 2019/11/04
–  Modified by: Takaaki Naganoya
–  Modified on: 2021/11/26

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

set aRes to holdNumberWithSignOnly("⑦Accessibility Inspector") of me
–> "⑦"

on holdNumberWithSignOnly(aStr as text)
  set aNSString to current application’s NSString’s stringWithString:aStr
  
  
return (aNSString’s stringByReplacingOccurrencesOfString:"[^\\U000024EA-\\U000024EA\\U00002460-\\U00002473\\U00003251-\\U000032BF\\U000024FF-\\U000024FF\\U00002776-\\U0000277F\\U000024EB-\\U000024F4\\U00002780-\\U00002789\\U0000278A-\\U00002793\\U000024F5-\\U000024FE]" withString:"" options:(current application’s NSRegularExpressionSearch) range:{0, aNSString’s |length|()}) as text
end holdNumberWithSignOnly

★Click Here to Open This Script 

Posted in Number Text | Tagged 10.13savvy 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

丸つき数字を数値にデコードする v2

Posted on 11月 26, 2021 by Takaaki Naganoya

丸つき数字を数値にデコードするAppleScriptです。よくよく考えるとこれまでに作っていなかったので、作っておきました。

AppleScript名:丸つき数字を数値にデコードする v2.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/11/26
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—

set dRes to decodeNumFromNumWithSign("⑮") of me
–> 15

–丸つき数字を数値にデコードする v2
on decodeNumFromNumWithSign(aStr as string)
  set numStr1 to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
  
set numStr2 to "❶❷❸❹❺❻❼❽❾❿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴"
  
set numStr3 to "➀➁➂➃➄➅➆➇➈➉"
  
set numStr4 to "➊➋➌➍➎➏➐➑➒➓"
  
set numStr5 to "⓵⓶⓷⓸⓹⓺⓻⓼⓽⓾"
  
–set numStr6 to "⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽⑾⑿⒀⒁⒂⒃⒄⒅⒆⒇"
  
–set numStr7 to "1︎⃣2︎⃣3︎⃣4︎⃣5︎⃣8︎⃣9︎⃣"
  
–set numStr8 to "⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛"
  
  
set nList to {numStr1, numStr2, numStr3, numStr4, numStr5}
  
  
repeat with i in nList
    set numTemp to contents of i
    
if numTemp contains aStr then
      using terms from scripting additions
        set bNum to offset of aStr in numTemp
      end using terms from
      
return bNum
    end if
  end repeat
  
return false
end decodeNumFromNumWithSign

★Click Here to Open This Script 

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

丸つき数字の除去と数値からの変換

Posted on 11月 26, 2021 by Takaaki Naganoya

丸つき数字を指定文字列から削除するAppleScriptと、1〜50の範囲の数値を丸つき数字に変換するAppleScriptです。

Keynoteの表に入っている丸つき数字のリナンバーを行うために、必要な処理を書いてみたものです。日本語環境でしかこういう文字は使わないことでしょう。

丸つき数字が文字コード上でところどころ切れているため、単純に調べるのに手間がかかりました。

AppleScript名:数字を丸つき数字に変換.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/11/26
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—

repeat with i from -10 to 100 by 1
  set aStr to convNumToNumWithSign(i) of me
  
log {i, aStr}
end repeat

on convNumToNumWithSign(aNum as number)
  if (aNum ≤ 0) or (aNum > 50) then return ""
  
set aStr to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
  
set bChar to character aNum of aStr
  
return bChar
end convNumToNumWithSign

★Click Here to Open This Script 

AppleScript名:丸つき数字を検出・削除
–  Original by: Shane Stanley
–  Created on: 2019/11/04
–  Modified by: Takaaki Naganoya
–  Modified on: 2021/11/26

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

set aRes to removeNumberWithSign("⓪①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿⓿❶❷❸❹❺❻❼❽❾❿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴➀➁➂➃➄➅➆➇➈➉➊➋➌➍➎➏➐➑➒➓") of me
–> "‍‍‍‍‍‍"

on removeNumberWithSign(aStr as text)
  set aNSString to current application’s NSString’s stringWithString:aStr
  
  
return (aNSString’s stringByReplacingOccurrencesOfString:"[\\U000024EA-\\U000024EA\\U00002460-\\U00002473\\U00003251-\\U000032BF\\U000024FF-\\U000024FF\\U00002776-\\U0000277F\\U000024EB-\\U000024F4\\U00002780-\\U00002789\\U0000278A-\\U00002793\\U000024F5-\\U000024FE]" withString:"" options:(current application’s NSRegularExpressionSearch) range:{0, aNSString’s |length|()}) as text
end removeNumberWithSign

★Click Here to Open This Script 

Posted in Number Text | Tagged 10.13savvy 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

AS Publisher v18–> v19

Posted on 11月 7, 2021 by Takaaki Naganoya

とくに新しいわけでもなんでもありませんが、「スクリプトエディタでオープン中のScriptをリンクつきのHTMLとして書き出すAppleScript」である「AS Publisher」の機能改修版です。前バージョンまではURLエンコーディング処理にpythonを呼び出して処理していましたが、Cocoaの機能を呼び出すように書き換えました。

# v18に処理のミスがあり、そのミスがOS側で「こういう間違いが多いから通しておこう」と見逃されていたのが厳密に処理されるようになったため、ミスの部分を修正しておきました

AppleScriptのリストをBlogなどに掲載する場合、WordPressやMarkdownの構文自動認識フォーマットを使って掲載されているものを見かけますが、そもそも「return return」(改行コードを返す)といった記述が許可されており、それらがきちんと構文色分けされているAppleScriptにおいて、単なるキーワードによる構文自動認識フォーマットが役立つわけがありません(知らずによく実装したもんですわ>オリジナル版を作った人)。

それ以前に「必要があったので」作ったAppleScriptでもあります。手元に残っている最古のバージョンは2005年の4月1日のタイムスタンプになっていますが、おそらくそれ以前から作っていたものでしょう。

# retMacOSpathList ハンドラで、ファイルパスをやたらとCastしている箇所がありますが、Mac OS X 10.5より前のAppleScriptではファイルパスの文字列のエンコーディングに問題を抱えていた(AppleScript側の文字列とのエンコーディング/ノーマライズの不整合)ので、その対策です。ただし、不必要なぐらい無駄な処理をしているので、参考にはなりません。Mac OS X初期の試行錯誤を強いられていた時代の遺物とでも思ってください

本Scriptおよびその派生版は、macOS標準装備のScript Menuに入れて実行することを想定しています。AppleScriptからスクリプトエディタを操作する場合に、Mac OS X 10.4の時代ではあまり動作が安定せず、もう少し後のバージョンのOSになるまで(10.5ぐらい?)、たいへんスリリングな(クラッシュが頻発する)Scriptingを強いられていました。

いまはそのあたりは安定していますが、ごく初期においては挙動が怪しい部分があったということです(その時期で知識が止まっている人はそういう認識のまま)。

話を戻しましょう。

AppleScriptのプログラムをBlogなどに掲載する際に、自分はこういう道具を作って使用しています。巨大なリストを掲載する場合には記事の文字数が膨大になってしまい、掲載をあきらめたこともありましたが、ほんのごく一部です。

このScriptをもとに、自分が使いやすいように(色指定とか)変更してみてもよいでしょう。

「動けばいい」ぐらいの割り切りで、秘伝のタレに継ぎ足してメンテナンスしてきましたが、HTMLタグで書式制御するよりはCSSで制御したほうがシンプルにできてよさそうな感じもします。

ファイル処理も、とくに「ここまでやる必要ってあったっけ?」という感想を持ってしまいます。なにぶん、2006年ごろに作ったものなので、自分で自分のプログラムを見ても違和感がものすごいですね。「OSの処理に対する不信感」がそこかしこに漂っています、、、、

AppleScript名:AS Publisher v19.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2014/11/09
–  Modified on: 2021/11/07
—
–  Copyright © 2006-2021 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property quotChar : string id 34

property headerCol : "0000CC" –"0000CC" –ヘッダー部分(濃い色)
property bodyBackCol : "EEFFFF" –"EEFFFF" –Script本文下地(薄い色)
property footerCol : "66FFFF" –"66FFFF" –スクリプトリンク部分

set a to path to me

set pName to "com.apple.ScriptEditor2"

using terms from application "Script Editor"
  tell application id pName
    if (count every document) = 0 then
      display dialog "スクリプトをエディタでオープンした状態で実行してください。" buttons {"OK"} default button 1 with icon 1
      
return
    end if
    
    
set aP to path of front document
    
if aP = "" then
      display dialog "スクリプトを保存してから実行してください。" buttons {"OK"} default button 1 with icon 1
      
return
    end if
    
    
tell front document
      set aInfo to properties
      
set curLang to name of language of aInfo –現在のOSA言語の名称を取得する
    end tell
    
    
–OSA Language名称をもとに色セットを変更する
    
changeColor(curLang) of me
    
    
set c to name of front document
    
    
set aF to retMacOSpathList(aP) of me
    
set htmlFilePath to retHTMLpath(aF) of me
    
    
set contText to contents of front document
    
set encText to makeEncodedScript(contText) of me
    
    
set newLinkText to "applescript://com.apple.scripteditor?action=new&script=" & encText
    
–set insLinkText to "applescript://com.apple.scripteditor?action=insert&script=" & encText
    
–set apndLinkText to "applescript://com.apple.scripteditor?action=append&script=" & encText
    
    
set comText to description of front document
    
    
set textList to every attribute run of front document
    
set textList_ref to a reference to textList
    
    
set colorList to color of every attribute run of front document
    
set colorList_ref to a reference to colorList
    
    
set aTest to contents of item 2 of textList
    
set asciiTest to id of aTest
  end tell
end using terms from

set tabChar to string id 9

–set TIDsList to {{"&", "&amp;"}, {">", "&gt;"}, {"<", "&lt;"}, {"¥"", "&quot;"}}
set TIDsList to {{"\\", "\"}, {"’", "’"}, {"&", "&amp;"}, {">", "&gt;"}, {"<", "&lt;"}, {"  ", "  "}, {string id 13, string id 10}, {string id 13, "<br>"}, {string id 10, "<br>"}, {"\"", "&quot;"}}
–set TIDsList to {{"&", "&amp;"}, {">", "&gt;"}, {"<", "&lt;"}, {"¥"", "&quot;"}}

set TIDsList_ref to a reference to TIDsList

set dataOut to {}
set dataOut_ref to a reference to dataOut

set iCounter to 1
repeat with i in textList_ref
  set j to contents of i
  
  
set curDelim to AppleScript’s text item delimiters
  
repeat with eachItem in TIDsList_ref
    set AppleScript’s text item delimiters to contents of item 1 of eachItem
    
set j to every text item of j
    
set AppleScript’s text item delimiters to contents of item 2 of eachItem
    
set j to j as string
  end repeat
  
set AppleScript’s text item delimiters to curDelim
  
  
set cText to RBG2HTML(item iCounter of colorList_ref) of me
  
  
set the end of dataOut_ref to "<font color=" & cText & ">" & j & "</font>"
  
set iCounter to iCounter + 1
end repeat

set htmlHeader to "<table width=" & quotChar & "100%" & quotChar & " border=" & quotChar & "0" & quotChar & "cellspacing=" & quotChar & "2" & quotChar & " cellpadding=" & quotChar & "2" & quotChar & ">
<tr>
<td bgcolor=\"#" & headerCol & "\"><font color=" & quotChar & "#FFFFFF" & quotChar & ">" & curLang & "名:" & c

if comText is not equal to "" then
  set comText to "<br><font size=" & quotChar & "2" & quotChar & ">【コメント】 " & comText & "</font><br>"
end if

set htmlHeader2 to "</font></td>
</tr>
<tr>
<td bgcolor=\"#" & bodyBackCol & "\"><font size=\"3\">"

set htmlFooter1 to "</font></td>
</tr>
<tr>
<td bgcolor=\"#" & footerCol & "\"><p><font size=\"2\"><a href=\"" & newLinkText & "\">★Click Here to Open This Script</a> </font></p>
</td>
</tr>
</table>
"

set dataText to htmlHeader & comText & htmlHeader2 & (dataOut as text) & htmlFooter1
set dataText to dataText as Unicode text

–set dDir to (path to desktop as text) & "index.html"
–write_to_file(dataText, htmlFilePath, false) of me
–saveInEncoding(dataText, htmlFilePath, "UTF8") of me –UTF8
write_to_file_Safely(dataText, htmlFilePath) of me

tell application id "com.apple.ScriptEditor2"
  display dialog "HTML書き出し完了" buttons {"OK"} default button 1 with icon 1 giving up after 1
  
return
end tell

on retHTMLpath(aF)
  tell application "Finder"
    –set aF to retMacOSpathList(aP) of me
    
set afA to aF as alias
    
set aInfo to info for afA
    
set aExt to name extension of afA
    
    
set aFileName to name of afA
    
set aFileName to aFileName as text
    
set aFileName to aFileName as Unicode text
    
    
set aFileName_rev to reverse of (every character of aFileName) as text
    
set parentF to ((parent of afA) as alias) as text
    
set htmlFileName to name of afA
    
set htmlFileName to htmlFileName as text
    
set htmlFileName to htmlFileName as Unicode text
    
    
    
if aExt is not equal to "" then
      set htmlFileNameText to ((reverse of (items ((length of aExt) + 2) thru -1 of aFileName_rev)) as text) & ".html"
    else
      set htmlFileNameText to (aFileName as text) & ".html"
    end if
    
set htmlFileNameFullPath to parentF & htmlFileNameText
  end tell
  
return htmlFileNameFullPath
end retHTMLpath

on makeEncodedScript(contText)
  (*

  set aList to every paragraph of contText
  set aClass to class of aList
  if aClass = list then
    set aLen to length of aList
  else
    set aLen to 1
  end if
  
  set aaList to {}
  
  set delim to AppleScript’s text item delimiters
  set AppleScript’s text item delimiters to "//piyomaru_replacement_temp//"
  set bList to aList as text
  set AppleScript’s text item delimiters to delim
  
  set aaList to (encodeURL(bList) of me) as Unicode text
  
  set search_string to "//piyomaru_replacement_temp//" as Unicode text
  set replacement_string to "%0A" as Unicode text
set bList to replace_chars(aaList, search_string, replacement_string) of me
*)

  
  
set aaList to (encodeURL(contText) of me) as Unicode text
  
  
return aaList
end makeEncodedScript

–RGB値からHTMLの色指定に変換
on RBG2HTML(RGB_values)
  — NOTE: this sub-routine expects the RBG values to be from 0 to 65536
  
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
  
set the the hex_value to ""
  
repeat with i from 1 to the count of the RGB_values
    set this_value to (item i of the RGB_values) div 256
    
if this_value is 256 then set this_value to 255
    
set x to item ((this_value div 16) + 1) of the hex_list
    
set y to item (((this_value / 16 mod 1) * 16) + 1) of the hex_list
    
set the hex_value to (the hex_value & x & y) as string
  end repeat
  
return ("#" & the hex_value) as string
end RBG2HTML

–安全なファイルの書き出し
on write_to_file_Safely(this_data, target_file)
  tell current application
    set finalPath to target_file
    
    
–テンポラリフォルダに一度書き出して、ターゲットのパスに移動  
    
set tmpFol to path to temporary items from system domain
    
set tmpName to do shell script "date +%Y%m%d%H%M%S"
    
set tmpPath to (tmpFol as string) & tmpName
    
    
–テンポラリのパスにファイル書き出し
    
try
      set the target_file to the tmpPath as text
      
set this_data to this_data as Unicode text
      
      
set the open_target_file to open for access file target_file with write permission
      
set eof of the open_target_file to 0 –つねにoverwrite mode(appendではなくて)
      
write this_data to the open_target_file starting at eof as «class utf8»
      
close access the open_target_file
      
    on error error_message
      try
        close access file target_file
      end try
      
return error_message
    end try
    
    
–ファイルの移動を行う
    
set tFilePOSIX to quoted form of POSIX path of target_file
    
set fPathPOSIX to quoted form of POSIX path of finalPath
    
set sText to "mv " & tFilePOSIX & " " & fPathPOSIX
    
try
      do shell script sText
    on error error_message
      return error_message
    end try
    
    
return true
  end tell
end write_to_file_Safely

on replace_chars(this_text, search_string, replacement_string)
  set AppleScript’s text item delimiters to the search_string
  
set the item_list to every text item of this_text
  
set AppleScript’s text item delimiters to the replacement_string
  
set this_text to the item_list as string
  
set AppleScript’s text item delimiters to ""
  
return this_text
end replace_chars

on encodeURL(origStr as string)
  set aStr to current application’s NSString’s stringWithString:origStr
  
set encodedStr to aStr’s stringByAddingPercentEncodingWithAllowedCharacters:(current application’s NSCharacterSet’s alphanumericCharacterSet())
  
return encodedStr as string
end encodeURL

on retMacOSpathList(aFile)
  set aPath to POSIX file aFile
  
set aPath to aPath as alias
  
set aPath to aPath as string
  
set aPath to aPath as Unicode text
  
set aliasFileList to aPath
  
return aliasFileList
end retMacOSpathList

–ファイルの追記ルーチン「write_to_file」
–追記データ、追記対象ファイル、boolean(trueで追記)
on write_to_file(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 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 write_to_file

on changeColor(aLang)
  if aLang = "AppleScript" then
    set headerCol to "0000CC" –"0000CC" –ヘッダー部分(濃い色)
    
set bodyBackCol to "EEFFFF" –"EEFFFF" –Script本文下地(薄い色)
    
set footerCol to "66FFFF" –"66FFFF" –スクリプトリンク部分
    
  else if aLang = "JavaScript" then
    set headerCol to "804000" –"0000CC" –ヘッダー部分(濃い色)
    
set bodyBackCol to "E2D3D3" –"EEFFFF" –Script本文下地(薄い色)
    
set footerCol to "E7AC53" –"66FFFF" –スクリプトリンク部分
  end if
end changeColor

★Click Here to Open This Script 

Posted in OSA Text | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy Script Editor Script Menu | 15 Comments

Stream Deck Softwareがバージョン5.1.2にバージョンアップ

Posted on 10月 16, 2021 by Takaaki Naganoya

ElgatoのStream Deck用ソフトウェアがバージョン5から5.1.2にバージョンアップしました。

従来は1台のStream Deckに対してプロファイルを複数登録して、「プロファイルを切り替え」アクションで1→2→3→4→1と、順送りで切り替えして、物理ボタンが15個であってもボタン数を超える機能を呼び出せるようにしてありました。

この仕組みはあらためて説明されると理解できるのですが、一目見て理解できるというものでもありません。自分も書籍を書くために仔細に調査を行うまで分かりませんでした。このあたりの「説明不足感」を解消するために「ページ切り替え」「ページインジケータ」も用意したのでしょうか。

物理ボタン数を超える機能を呼び出すための「プロファイルを切り替え」アクションであったり、「フォルダ」アクションであったり、「ページ切り替え」アクションであったり。同じ働きを行う機能を、見せ方を変えて複数実装してあるというのは、それだけ「問題点」だと(販売・営業的に、)みなされているためでしょうか。

より多くのアクションをボタン上にホスティングするために、プロファイル切り替えアクションに、ページ切り替えアクション、ページ表示アクション、フォルダ移動アクションなど操作系のアクション配置ボタンが増え、実質的にSD上に配置できるアクションが減ってしまう(6ボタンの最小のSDの場合には切り替え用で半分埋まる?)わけで、購入時によりボタン数の多いSDモデルへの誘導を行いたいのか、実ボタン以上のアクションをホスティングできることを訴求したいのか……それは自分にはわかりませんが、力を入れている場所であることは確かです。

最終的にはフェイスプレート部分に透明窓を追加して、プロファイル切り替えやページ切り替え、フォルダ切り替えなどの追加表示をSDの画面上で行うといったあたりに「落とし所」がありそうです。

Posted in news | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy Stream Deck | Leave a comment

Numbersの書類上で選択中の範囲のセルの値をシャッフル

Posted on 8月 24, 2021 by Takaaki Naganoya

Numbersの書類上で選択中の範囲のセルの値をシャッフルするAppleScriptです。Numbers書類の表の上で節度ある範囲(テスト用なので…100個ぐらい?)のセルを選択して実行し、シャッフされたデータをNumbersに描き戻します。

# 単なるデモScriptなので、数千とか数万個のセルを選択した場合には、CSVに書き出してNumbersでオープンし、そのデータ内容をコピペで元のNumbersに書き戻したほうが処理が速いことでしょう。

実際にmacOS 12 beta5でどの程度、処理速度が向上したかを確認するために書いてみました。

–> Watch macbookpro10,1_10.14_macminim1_12 demo

上記の画像で左がMacBookPro 10,1(Intel Core i7 2.66GHz、macOS 10.14.6)、右がMacmini9,1(Apple M1 3.2GHz、macOS 12 beta5)です。

これまで使用してきたMacBook Pro Retina 2012と現行のM1 Mac miniの速度差は気になります。macOS 11上ではM1 Mac miniのほうが10倍遅かったわけですが、最新のmacOS 12 beta5ではどうなのか。

きっちり両方とも揃えてスタートできているわけではありませんが、それでもM1のほうが2倍強ほど高速になっていることがわかります。このぐらいだと友人知人におすすめしても恨まれないレベルだと思います。

ただ、お勧めするにしてもmacOS 12の正式版が出てからですね。自分のMac App Storeに出しているアプリも、macOS 12がリリースされる前にUniversal Binary版を出すと「M1対応にしても速くなっていない」などと文句を言われそうです。

逆に、macOS 12の正式版がリリースされたら「Intel版のままなのに信じられないほど速くなった」ということになりそうです。

AppleScript名:セルの値のシャッフル.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/08/22
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.7" — High Sierra (10.13) or later
use framework "Foundation"
use framework "GameplayKit"
use scripting additions

tell application "Numbers"
  tell front document
    tell active sheet
      try
        set theTable to first table whose class of selection range is range
      on error
        return –何も選択されてなかった場合は終了
      end try
      
      
tell theTable
        set mySelectedRanges to value of every cell of selection range
        
set cellList to cell of selection range
      end tell
    end tell
  end tell
end tell

–1D Array Shuffle
set anArray to current application’s NSArray’s arrayWithArray:mySelectedRanges
set randomArray to anArray’s shuffledArray() as list — requires macOS 10.12

tell application "Numbers"
  tell front document
    tell active sheet
      tell theTable
        repeat with i from 1 to (length of cellList)
          tell item i of cellList
            set value to item i of randomArray
          end tell
        end repeat
      end tell
    end tell
  end tell
end tell

★Click Here to Open This Script 

Posted in list | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy Numbers | Leave a comment

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • 開発機としてM2 Mac miniが来たのでガチレビュー
  • macOS 15, Sequoia
  • 指定のWordファイルをPDFに書き出す
  • Pages本執筆中に、2つの書類モード切り替えに気がついた
  • Numbersで選択範囲のセルの前後の空白を削除
  • メキシカンハットの描画
  • Pixelmator Pro v3.6.4でAppleScriptからの操作時の挙動に違和感が
  • AdobeがInDesign v19.4からPOSIX pathを採用
  • AppleScriptによる並列処理
  • Safariで「プロファイル」機能を使うとAppleScriptの処理に影響
  • Cocoa Scripting Course 続刊計画
  • macOS 14.xでScript Menuの実行速度が大幅に下がるバグ
  • AppleScript入門③AppleScriptを使った「自動化」とは?
  • Keynote/Pagesで選択中の表カラムの幅を均等割
  • デフォルトインストールされたフォント名を取得するAppleScript
  • macOS 15 リモートApple Eventsにバグ?
  • Keynote、Pages、Numbers Ver.14.0が登場
  • macOS 15でも変化したText to Speech環境
  • AppleScript入門① AppleScriptってなんだろう?
  • Numbersで最前面の書類のすべてのシート上の表の行数を合計

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 (132) CotEditor (66) Finder (51) iTunes (19) Keynote (117) 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
  • 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年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