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

タグ: 13.0savvy

display drop dialogライブラリをv1.5にアップデート

Posted on 11月 4, 2023 by Takaaki Naganoya

電子書籍「AppleScript最新リファレンスv2.8対応」の添付Scriptの中にこのAppleScriptライブラリを呼び出しているものがあったので、macOS 11以降のUIに応じて各種サイズを変更した「display drop dialog」のバージョン1.5をリリースしました。

複数のUTIを指定して、複数タイプの書類のドラッグ&ドロップを受け付けるようにしました。.scptと.scptdのドラッグ&ドロップを受け付けるとか。

また、本ライブラリではダイアログ上でのファイルの並び順もドラッグ&ドロップで変更できるため、複数のPDFをドラッグ&ドロップで指定して、処理順をダイアログ上で変更するといった用途に用いることを想定しています。

AppleScriptをmacOS標準搭載のスクリプトメニューから呼び出したような場合に、処理対象のファイルをドラッグ&ドロップで指定する場合のファイル受け付けのインタフェースとして用意したものです。

–> Download displayDropDialog15(Install to ~/Libraries/Script Libraries/ folder)

AppleScript名:accept AppleScript documents.scpt
use dropLib : script "display drop dialog" version "1.5"

set aMainMes to "Drop AppleScript"
set aSubMes to "Drag and Drop AppleScript files to Table (.scpt & .scptd)"
set aUTI to {"com.apple.applescript.script-bundle", "com.apple.applescript.script"}
set execButtonTitle to "Execute"

set aRes to (display drop dialog aUTI main message aMainMes sub message aSubMes with initial folder "" OK button title execButtonTitle)

★Click Here to Open This Script 

Posted in dialog file File path GUI Library | Tagged 11.0savvy 12.0savvy 13.0savvy 14.0savvy | Leave a comment

macOS 13.6.2アップデート Cocoa-AppleScript Applet修正はなし

Posted on 10月 28, 2023 by Takaaki Naganoya

macOS 13.6.2アップデートが配信されました。Cocoa-AppleScript AppletがmacOS 13.xの途中で動かなくなり、macOS 13.6.x台で修正されるのではないか? などと思っていましたが、そういう状態にはなっていないようです。

ちなみに、macOS 13.xよりももっと古いOSで「Cocoa-AppleScript Applet」のアプレットを作成し、そこから実行バイナリ部分(/Contents/MacOS/CocoaApplet)を抜き出して、macOS 13.x上で作ったCocoa-AppleScript Appletの同一バイナリを削除して入れ替えると動く、という検証報告も入っています。

正直、Cocoa-AppleScript Appletは登場以来、「こんなので使えるか!?」という存在でした。その後OS X 10.10で一般のAppleScript実行環境でCocoa呼び出しが許可されてから、Scripter側にCocoa活用のノウハウが蓄積され、「標準環境よりもできることが多い」とのことで再評価されたものでもあります。

Posted in Bug Cocoa-AppleScript Applet news | Tagged 13.0savvy | Leave a comment

Finder上で選択中のASバンドル書類をオープンしてscpt形式で再保存

Posted on 10月 20, 2023 by Takaaki Naganoya

Finder上で選択中のAppleScriptバンドル形式書類をスクリプトエディタでオープンして、scpt形式で保存し直すAppleScriptです。

スクリプトエディタのコンテクストメニューが.scpt形式しか認識しないので、バンドル形式のScriptを変換するために作ったものです。

Finderの選択中のファイルをフィルタするのに、フィルタ参照ではなくUTIを求めて判定しています。

「AppleScript最新リファレンスv2.8対応」の付録Scriptの加工用に作ったものです。バンドル形式への変換は書いてあったものの、scpt形式に変換するものは書いていなかったので急遽、用意しました。

AppleScript名:Finder上で選択中のASバンドル書類をオープンしてscpt形式で再保存.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/10/20
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSPredicate : a reference to current application’s NSPredicate
property NSURLTypeIdentifierKey : a reference to current application’s NSURLTypeIdentifierKey

on run
  set aResList to main("com.apple.applescript.script-bundle") of me
  
  
set ngList to {}
  
  
repeat with i in aResList
    set anAlias to contents of i
    
set aRes to saveAppleScriptAsScript(anAlias) of me
    
    
if aRes = false then
      set the end of ngList to contents of i
    end if
  end repeat
  
  
return ngList
end run

–scptdファイルをaliasで渡すと、scptファイルで同じ場所に保存し直す
on saveAppleScriptAsScript(aFile)
  set dPOSIX to POSIX path of aFile
  
if dPOSIX ends with "/" then
    set dPOSIX to (strings 1 thru -2 of dPOSIX)
  end if
  
  
–フルパスから、拡張子を付け替える
  
set newPath to changeExtFromPath(dPOSIX, "scpt") of me
  
set newFile to POSIX file newPath
  
  
tell application id "com.apple.scripteditor2"
    try
      open aFile
      
      
tell front document
        check syntax
      end tell
      
      
save front document as "script" in file newFile
      
close front document without saving
      
return true
    on error
      return false
    end try
    
  end tell
end saveAppleScriptAsScript

–POSIX pathの拡張子を付け替える
on changeExtFromPath(aPath, newExt)
  set pathString to current application’s NSString’s stringWithString:aPath
  
set newPath to ((pathString’s stringByDeletingPathExtension())’s stringByAppendingPathExtension:newExt) as string
  
return newPath
end changeExtFromPath

on main(acceptUTI)
  tell application "Finder"
    set aSel to selection as alias list
  end tell
  
  
set aList to {}
  
  
repeat with i in aSel
    set anAlias to contents of i
    
set aUTI to getUTIfromPath(anAlias) of me
    
if aUTI is not equal to missing value then
      set uRes to filterUTIList({aUTI}, acceptUTI) of me
      
      
if uRes is not equal to {} then
        set the end of aList to contents of i
      end if
    end if
  end repeat
  
  
return aList
end main

–AliasからUTIを求める
on getUTIfromPath(anAlias)
  set aPOSIXpath to POSIX path of anAlias
  
set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath
  
if aURL = missing value then return missing value
  
set aRes to aURL’s resourceValuesForKeys:{current application’s NSURLTypeIdentifierKey} |error|:(missing value)
  
if aRes = missing value then return missing value
  
return (aRes’s NSURLTypeIdentifierKey) as string
end getUTIfromPath

–UTIリストが指定UTIに含まれているかどうか演算を行う
on filterUTIList(aUTIList, aUTIstr)
  set anArray to NSArray’s arrayWithArray:aUTIList
  
set aPred to NSPredicate’s predicateWithFormat_("SELF UTI-CONFORMS-TO %@", aUTIstr)
  
set bRes to (anArray’s filteredArrayUsingPredicate:aPred) as list
  
return bRes
end filterUTIList

★Click Here to Open This Script 

Posted in file File path filter | Tagged 12.0savvy 13.0savvy 14.0savvy Finder Script Editor | Leave a comment

新刊発売 AppleScript最新リファレンス v2.8対応

Posted on 10月 13, 2023 by Takaaki Naganoya

ようやく完成しました。最初の「AppleScript最新リファレンス macOS 10.11対応」の刊行から7年。完全刷新のアップデート版を刊行しました。PDF 974ページです。

→ 販売ページ

最新OS環境に合わせてアップデート

現行のAppleScript v2.8環境に合わせ、macOS 12/13/14を対象としたアップデートを行いました。可能なかぎり、macOS 10.13あたりからの各アプリケーションの用語辞書の変化などを追いかけ、それぞれのAppleScript実行プログラムのセキュリティ上の制約について、ベンチマークScriptを用いて評価も行なっています。

より広く、よりわかりやすく、よりくわしく

最初の「AppleScript最新リファレンス」(483ページ)から大幅にページを増やして974ページ。その分、解説範囲を広げています。

また、解説内容の難易度や想定ユーザーのレベルに分けた章構成を採用しています。

Script入門者向けに有用な情報(入門編)、Script利用者向けに有用な情報(利用編)、実際にScriptを書くユーザー向けに有用な情報(実践編)、困ったときに調べると便利な情報(資料編)など。

本書の付録は、スクリプトエディタのコンテクストメニューから呼び出すSnipet Scriptの「Piyomaru Context Menu Assistant」最新版、スクリプトエディタのテンプレートとして呼び出せる「Piyomaru Script Templates」、そしてGUI Scriptingの強力な助っ人「Dynamic Menu Clicker」などで構成されます(これからまとめて添付します。ちょっと手直しも必要なので)。

これからScriptに手を出そうかなという人にも、すでに使っているという人にも有用と思われる情報をわかりやすくまとめた1冊です。

■特集
AppleScriptv2.8の全貌
Shortcuts Events
OSAXなき時代のAppleScript命令拡張
各種セキュリティ制限を解除する
各種支援プログラムの現状
macOS標準装備&Apple純正アプリのAppleScript対応度解説
Finder/Automator/カレンダー/連絡先/メール/マップ/メッセージ/ミュージック/メモ/写真/システム設定/プレビュー/QuickTime Player/リマインダー/Safari/スクリプトエディタ/ショートカット/ターミナル/テキストエディット/tv/VoiceOver/画面共有/コンソール/System Information/Keynote/Pages/Numbers/Claris FileMaker Pro/Xcode/Apple Configurator/Garageband/iMovie/Instruments

■入門編
AppleScriptの世界を形作るもの
macOS標準搭載アプリケーションで AppleScript対応機能を持つもの
AppleScriptを実行できる、 さまざまなmacOS標準搭載ツール
AppleScriptを実行できる、 サードパーティのハード&ソフト
AppleScriptってなんだろう?
スクリプトエディタの使い方
「構文確認」時に行われること
Scriptを書く前に準備しておくこと
AppleScript最速マスター
文法編
AppleScript予約語一覧
AppleScript最新リファレンス
tellブロック/アクション/ダイアログ表示/コマンド/他の言語呼び出し/序数/制御構文/文字列操作/システム日付/データ型/定数/変数・プロパティ宣言/関数/演算子/パス関連/ファイル入出力/ローカライズ関連/テキスト要約/Webサービス呼び出し/フィルタ参照/サブルーチン宣言/無意味語/クリップボード制御/音量制御/スクリプトオブジェクト/その他
アプリケーションへの命令パターン
Script Debuggerとは?
Finder用語辞書攻略ガイド
Finderを使った定型処理
コラム GUIアプリの操作に影響を与えるFinder設定項目

■利用編
Script Menuの使い方
FastScripts 3
アプリケーションごとのScript Menu
フォルダアクション解説
Terminalから使うAppleScript
各種プラグインAppleScript
PDF Workflow Script解説
Mail Plugin Script解説
コンテクストメニューから呼び出す
廃止されたプラグインAppleScript
その他のAppleScriptランチャー〜スイッチコントロール/Automator/ショートカット/音声コントロール/Adobe Illustrator 2023/Adobe InDesign 2023/Keyboard Maestro/Hammerspoon/Service Station/Dropzone 4/Visual Studio Code/CotEditor+PowerPack/Xojo 2023/Live Code/Elgato Stream Deck
制限つきユーザーアカウント&制限つきマシン環境下のAppleScript
ペアレンタルコントロールとAppleScript
MDMによる制限環境下のAppleScript

■実践編
OSバージョン番号確認
ランタイム環境を知る
ハードウェア情報
GUI Scriptingの概要
AppleScriptからネット上の機能を手軽に活用
REST API呼び出し
CDN上のJavaScriptライブラリ呼び出し
ドロップレットを作らなくても大丈夫なScript運用術
Cocoa Scripting入門
対応Framework一覧(macOS 13/14)
Mac App StoreでAppleScriptで作ったアプリを販売
Piyomaru コンテクストメニューアシスタント
Piyomaru Script Templates

■資料編
AppleScriptと相性のよくない技術
各アプリケーションにおけるさまざまな座標系
独自マクロ言語内に記述するAppleScript〜Microsoft Office VBA/Claris FileMaker Pro Script Step
iOSデバイスとの連携
下準備
iOSデバイスからAppleScriptを実行する
iOSデバイス上の情報を更新する
AppleScriptで電話をかける
AppleScriptでSMSを送信する
iPhone/iPadとFaceTimeで通話する
リソースリファレンス〜Predicate文/UTI/アイコン/ディスクイメージ
AppleScriptの歴史
macOSとAppleScriptの要素技術史
AppleScriptの歴史 macOS編
AppleScriptの歴史 Classic MacOS編
AppleScript FAQs
エラー番号とエラーメッセージ
AppleScriptのエラー・コード表
キーコード表
キー入力シミュレーション用キーコード
あとがき

Posted in Books news | Tagged 12.0savvy 13.0savvy 14.0savvy | Leave a comment

macOS 13.6.1アップデート。Cocoa-AppleScript Appletの修正はなし

Posted on 10月 4, 2023 by Takaaki Naganoya

macOS 13.6.1アップデートがβ段階を経由せずに配信されました。セキュリティ上の問題を解消するためのもの、とのことです。

念のために試してみましたが、macOS 13.x上で実行ができなくなっているCocoa-AppleScript Appletランタイムは、依然として実行できません。彼らがこれを直す気があるのかどうか、まったくわかりません。

Posted in Cocoa-AppleScript Applet news | Tagged 13.0savvy | Leave a comment

Cocoa-AppleScript Appletランタイムが動かない?

Posted on 9月 22, 2023 by Takaaki Naganoya

AppleScriptObjC(Cocoa Scripting)の実行環境は大きく分けて3つあります。

1つ目は、Script EditorもしくはScript Debugger上で動かすもの、あるいはアプレットの書き出しを行なったもの。実行環境IDを取得すると、AppletとDropletは別のIDが返ってきますが、だいたい同じものです。

2つ目は、Xcode上で作成するCocoaアプリケーションです。AppleScriptでアプリを作成して、Mac App Store上で販売することもできます。かなり多くのCocoaの機能を利用できます。

3つ目が、これら2つの中間的な機能を持つCocoa AppleScript Appletです。Script Editorのファイル>テンプレートから新規作成>Cocoa-AppleScript Applet.appを実行すると編集可能になります。

Cocoa-AppleScript Appletは、Script Editor上のCocoa Scriptと同様の機能が使える上に、アプリケーション由来のイベント(起動中であるとか、起動終了したとか)を利用できます。

Cocoa-AppleScript Appletが登場したOS X 10.7時代、Xcode上のようにInterface Builderで手軽にGUIが作成できるわけでもなく、Script Editor上で普通に動かすScriptのようにログを表示してデバッグができるわけでもなく、何か明確な用例が存在するわけでもないため「これでどないせーっちゅーんじゃ?」と、とても手を出せないものと感じました。自分はこれを明確な「失敗作」として評価していました。この環境を嬉々として使っている人物といえば、edama2氏ぐらいのものです。

その後、macOS 10.10以降で通常のScript Editor上で動かすAppleScriptでもCocoaの機能が利用できるようになったため、Cocoa Scriptingのノウハウが蓄積され、「より高機能なCocoa Scripting環境」としてCocoa-AppleScript Appletが再評価されるようになりました。

Script Editor上で記述するCocoa Scriptで機能的に不十分だと感じるようになる場面で、Xcodeを使ってフル機能のアプリケーションを作るほどでもない、という状況において、Cocoa-AppleScript Appletという第3の選択肢が存在していることの意義はあったのです(使っているユーザーがめちゃくちゃ少ないとは思いますが)。

そして、ごくたまに様子を見るぐらいだったCocoa-AppleScript Applet環境ですが、最近(macOS 13.x上で)動かないという声が寄せられるようになりました。自分も動かないことを確認しています。テンプレートから1行も追加していない状態でも動かないので、これは明らかにApple側のミスでしょう。

バグレポートすれば直してもらえるのかもしれませんが、こうした情報が共有されるとか、Appleがドキュメントを出すようにしないと、いつも不手際をこっそり誤魔化すだけで「給料をもらって毎日バグを作るAppleエンジニア」「Appleのエンジニアは製品を作らない。バグを作る」といった批判をかわせない状態になることでしょう。

これは、年表を頻繁に作る立場の人間からいえば、Mac OS X 10.3で「is in」演算子が動作しなかったのと同じぐらいの大規模なバグに見えます。

本件、macOS 14RC上でも同様に発生しています。おおかた、「証明書の期限が切れている」といったたぐいのトラブルだと思っています。

Posted in Bug Cocoa-AppleScript Applet | Tagged 13.0savvy 14.0savvy | 2 Comments

Keynote/Pages/Numbers v13.2がリリースされる

Posted on 9月 22, 2023 by Takaaki Naganoya

iWork……という言葉は最近はあまり使われないようなので、Keynote、Pages、Numbersと呼びますが……これらのアップデート版v13.2が公開されました。AppleScript用語辞書の修正、追加はありません(作成できるグラフ形式が増えているのですが、ASから作成できるようにはなっていません)。

メジャーアップデートのv14.0などではないので、本バージョンは堅実で小刻みな機能アップデート版といえるでしょう。

3Dオブジェクトを格納するUSDZファイルをデータとして挿入できたりアニメーション表示(Keynote)できたり、新しいテーマが追加されたり、その他SVG画像を素材として利用できるようになったもようです。

USDZ形式のファイルを扱えるのは、いまのところ手元のアプリケーションではXcodeとPreview.appのみ。

SVGについては、いろいろ増えてきています。

こうした各種書類形式をキーにして、さまざまなアプリケーションを連携させられるという情報を提供する件をAppleのWWDRに提案したことがありましたが、どこのチームも興味を持たなかったとのこと。

USDZ形式データについては、数年前からこの形式データの利用を広めたいという「意図」が見えたので、いろいろ情報収集はすすめてきました。iWork Appsでサポートするということで、1段階利用が広がったというところですが、たとえばKeynoteで3Dを前提としたアニメーションやトランジッションが実装される、という機能が整備されるまでは単なる素材が1つ増えたぐらいでしょう。

Keynoteに3Dトランジッションや3Dアニメーションを追加するぐらいのことは、とっくの昔から検討されていたと思われますが、おそらく実装してみると「思ったよりも効果的ではない」という結論になったのでしょう。Vision ProのようなxRデバイスで閲覧するという「ブラウズ環境」を整備できたことにより、USDZ形式のデータを広くサポートする「価値」が生まれると踏んだのでしょう。

Vision Proが成功を収めるか、誰もが記憶から追い出したくなるような失敗として記録されるかは不明ですが、USDZ形式の利用が広くサポートされれば、それは多くの人々に役立つものとなることでしょう。

Posted in news | Tagged 12.0savvy 13.0savvy 14.0savvy Keynote Numbers Pages | Leave a comment

Calendar.appのイベントにAppletを添付できる?

Posted on 9月 22, 2023 by Takaaki Naganoya

Calendar.appのイベント(予定)に、ファイルを添付できるようになっています。ここに、AppleScriptアプレットを添付して実行することで、タイマー実行アプリとしてCalendar.appを利用する、というスタイルが初期のMac OS Xで見られました。Mac OS X 10.6ぐらいまででしょうか。

その後、どうもCalendar.appのイベントにAppletを添付しても実行されなくなった、という話をよく聞くようになりました。

自分も、タイマー実行アプリとしてCalendar.appは「使えないもの」と判断し、自前でタイマー機能などを作り込んで使ってきました。確実さでいえば、これは実に確実ではあるものの、それを外部に提供するのかという話については、いい「落とし所」を見出せない感じではあります。

こちらもタダで出すつもりはないけれど、これどうせ国内外のScripter連中は買わないよね、というところで話が止まっているものでもあります。モノがモノなので、Mac App Storeにも出せないでしょう(あらかじめ、どういうアプリを操作する、という設定を行なって提出する必要があるので。事前にわかるわけがない)。

そんな中、X(旧称Twitter)上で「Calendar.appをAppleScript Appletのタイマー起動用に使っている」という話を聞きつけ、その内容について実際にやりとりをして、自分の手元でもできることを確認しました。

その時点での自分の理解では、「イベントにAppletを添付して、イベントのアクションで『添付ファイルをオープンする』という指定を行えばOK」だという話だと納得しました。なるほど、自分は使い方を誤解していたのか、と。

しかし、その翌日に「別のAppletも添付して試してみよう」ということで、別のイベントを作成して別のAppletを添付して「添付ファイルをオープン」させてみたものの、今度はイベントの指定時刻に通知は来るものの、添付ファイルであるAppletは起動されませんでした。

Calendar.app自体のバグなのか、それともイベントへのApplet添付・実行には何か気づかないパラメータが存在しているのか?(イベント登録時のアカウントであるとか、ローカルの通知だけにしておかないとダメとか) そのあたりがまったく不明です。

昨日、一昨日ぐらいの段階でCalendar.appへのAppletの添付・実行は2・3度成功していたので、なかなか謎なところがあるものです。

Posted in Bug Calendar | Tagged 13.0savvy Calendar | Leave a comment

macOS 14の変更がmacOS 13にも反映

Posted on 9月 21, 2023 by Takaaki Naganoya

macOS 14RCをさわって「システム設定」をAppleScriptから操作し、目的のPaneをIDで指定して表示できることを確認しました。

macOS 13に戻ってきて資料を作成(macOS 14を信用していないので)。「macOS 13でも動いてみたりして?」と、冗談半分にmacOS 14用のScriptを走らせたら……動いてしまいました。

各PaneのIDやnameを取得でき、指定IDのPaneを表示でき、現在表示中のPaneの情報を取得できます。

厳密に「いつから」この状態になっていたのかは不明ですが、macOS 13.5あたりでしょうか? 自分の環境はmacOS 13.6betaなので、13.5/13.5.1の状況は確認のしようがありませんが、OSのマイナーバージョンアップ時にこうしたまともな改修を行うなんて、前代未聞です。よほど、全世界的に文句を言われたのでしょう。

name ID
(ユーザーの名前) com.apple.systempreferences.AppleIDSettings*AppleIDSettings
ファミリー com.apple.Family-Settings.extension*Family
Wi‑Fi com.apple.wifi-settings-extension
Bluetooth com.apple.BluetoothSettings
ネットワーク com.apple.Network-Settings.extension
VPN com.apple.NetworkExtensionSettingsUI.NESettingsUIExtension
通知 com.apple.Notifications-Settings.extension
サウンド com.apple.Sound-Settings.extension
集中モード com.apple.Focus-Settings.extension
スクリーンタイム com.apple.Screen-Time-Settings.extension
一般 com.apple.systempreferences.GeneralSettings
外観 com.apple.Appearance-Settings.extension
アクセシビリティ com.apple.Accessibility-Settings.extension
コントロールセンター com.apple.ControlCenter-Settings.extension
SiriとSpotlight com.apple.Siri-Settings.extension
プライバシーとセキュリティ com.apple.settings.PrivacySecurity.extension
デスクトップとDock com.apple.Desktop-Settings.extension
ディスプレイ com.apple.Displays-Settings.extension
壁紙 com.apple.Wallpaper-Settings.extension
スクリーンセーバ com.apple.ScreenSaver-Settings.extension
省エネルギー com.apple.Battery-Settings.extension*EnergySaverPreferences
ロック画面 com.apple.Lock-Screen-Settings.extension
ログインパスワード com.apple.Touch-ID-Settings.extension*TouchIDPasswordPrefs
ユーザとグループ com.apple.Users-Groups-Settings.extension
パスワード com.apple.Passwords-Settings.extension
インターネットアカウント com.apple.Internet-Accounts-Settings.extension
Game Center com.apple.Game-Center-Settings.extension
キーボード com.apple.Keyboard-Settings.extension
マウス com.apple.Mouse-Settings.extension
ゲームコントローラ com.apple.Game-Controller-Settings.extension
プリンタとスキャナ com.apple.Print-Scan-Settings.extension
AppleScript名:すべてのPaneの情報を取得.scpt
tell application "System Settings"
  set aList to properties of every pane
  
–> {{class:pane, name:"外観", id:"com.apple.Appearance-Settings.extension"}, {class:pane, name:"ロック画面", id:"com.apple.Lock-Screen-Settings.extension"}, {class:pane, name:"キーボード", id:"com.apple.Keyboard-Settings.extension"}, {class:pane, name:"ファミリー", id:"com.apple.Family-Settings.extension*Family"}, {class:pane, name:"Wi‑Fi", id:"com.apple.wifi-settings-extension"}, {class:pane, name:"デスクトップとDock", id:"com.apple.Desktop-Settings.extension"}, {class:pane, name:"Bluetooth", id:"com.apple.BluetoothSettings"}, {class:pane, name:"壁紙", id:"com.apple.Wallpaper-Settings.extension"}, {class:pane, name:"SiriとSpotlight", id:"com.apple.Siri-Settings.extension"}, {class:pane, name:"マウス", id:"com.apple.Mouse-Settings.extension"}, {class:pane, name:"プライバシーとセキュリティ", id:"com.apple.settings.PrivacySecurity.extension"}, {class:pane, name:"機能拡張", id:"com.apple.ExtensionsPreferences"}, {class:pane, name:"プロファイル", id:"com.apple.Profiles-Settings.extension"}, {class:pane, name:"省エネルギー", id:"com.apple.Battery-Settings.extension*EnergySaverPreferences"}, {class:pane, name:"一般", id:"com.apple.systempreferences.GeneralSettings"}, {class:pane, name:"情報", id:"com.apple.SystemProfiler.AboutExtension"}, {class:pane, name:"ソフトウェアアップデート", id:"com.apple.Software-Update-Settings.extension"}, {class:pane, name:"ストレージ", id:"com.apple.settings.Storage"}, {class:pane, name:"AirDropとHandoff", id:"com.apple.AirDrop-Handoff-Settings.extension"}, {class:pane, name:"ログイン項目", id:"com.apple.LoginItems-Settings.extension"}, {class:pane, name:"言語と地域", id:"com.apple.Localization-Settings.extension"}, {class:pane, name:"日付と時刻", id:"com.apple.Date-Time-Settings.extension"}, {class:pane, name:"共有", id:"com.apple.Sharing-Settings.extension"}, {class:pane, name:"Time Machine", id:"com.apple.Time-Machine-Settings.extension"}, {class:pane, name:"転送またはリセット", id:"com.apple.Transfer-Reset-Settings.extension"}, {class:pane, name:"起動ディスク", id:"com.apple.Startup-Disk-Settings.extension"}, {class:pane, name:"集中モード", id:"com.apple.Focus-Settings.extension"}, {class:pane, name:"ゲームコントローラ", id:"com.apple.Game-Controller-Settings.extension"}, {class:pane, name:"スクリーンタイム", id:"com.apple.Screen-Time-Settings.extension"}, {class:pane, name:"長野谷隆昌", id:"com.apple.systempreferences.AppleIDSettings*AppleIDSettings"}, {class:pane, name:"VPN", id:"com.apple.NetworkExtensionSettingsUI.NESettingsUIExtension"}, {class:pane, name:"ディスプレイ", id:"com.apple.Displays-Settings.extension"}, {class:pane, name:"プリンタとスキャナ", id:"com.apple.Print-Scan-Settings.extension"}, {class:pane, name:"Game Center", id:"com.apple.Game-Center-Settings.extension"}, {class:pane, name:"インターネットアカウント", id:"com.apple.Internet-Accounts-Settings.extension"}, {class:pane, name:"コントロールセンター", id:"com.apple.ControlCenter-Settings.extension"}, {class:pane, name:"ネットワーク", id:"com.apple.Network-Settings.extension"}, {class:pane, name:"スクリーンセーバ", id:"com.apple.ScreenSaver-Settings.extension"}, {class:pane, name:"アクセシビリティ", id:"com.apple.Accessibility-Settings.extension"}, {class:pane, name:"サウンド", id:"com.apple.Sound-Settings.extension"}, {class:pane, name:"ユーザとグループ", id:"com.apple.Users-Groups-Settings.extension"}, {class:pane, name:"パスワード", id:"com.apple.Passwords-Settings.extension"}, {class:pane, name:"通知", id:"com.apple.Notifications-Settings.extension"}, {class:pane, name:"ログインパスワード", id:"com.apple.Touch-ID-Settings.extension*TouchIDPasswordPrefs"}, {class:pane, name:"SwiftDefaultApps", id:"cl.fail.lordkamina.SwiftDefaultApps"}, {class:pane, name:"SwitchResX", id:"fr.madrau.switchresx.prefpane"}}
end tell

★Click Here to Open This Script 

AppleScript名:現在表示中のPaneの情報を取得.scpt
tell application "System Settings"
  set aList to properties of current pane
  
–> {class:pane, name:"外観", id:"com.apple.Appearance-Settings.extension"}
end tell

★Click Here to Open This Script 

AppleScript名:WiFiのPaneを表示.scpt
tell application "System Settings"
  reveal pane id "com.apple.wifi-settings-extension"
end tell

★Click Here to Open This Script 

Posted in news System | Tagged 13.0savvy 14.0 System Settings | 1 Comment

Digital Hub Scriptingの謎

Posted on 9月 15, 2023 by Takaaki Naganoya

「AppleScript最新リファレンスv2.8」の作成で、一番手間がかかったのは、Markdownで書いた原稿をPagesに移し替えることでした。Markdownでは雑なレイアウトを作ることはできても、結局のところ「表」の制御がまったくできないために、Markdownで作り続けることは無理だと判断しました。掲載プログラムリストについても、行折り返しが不自然になる箇所があり、そのために全体の文字サイズが変わってしまうなどの「不可解な挙動」がいくつか見られました。

とっくの昔に結論が出ていたことですが、もう本作りにMarkdownは利用していません。

そして、作り直すさいにさまざまなコンテンツを再チェックすることで、なるべく間違いがなくなるように努めてきました。この表もその1つです。

昔作ってそのまま使い回してきましたが、Digital Hub Scriptingの箇所が不自然です。

Digital Hub ScriptingはmacOS 10.13の時点でSystem Eventsに移行した、と考えていました。でも、今日、ねんのために確認してみたら、

あれっ?(^ー^::

Digital Hub Scriptingについては、個人的な使用頻度がおそろしく低く、あまり使ってきませんでした。System EventsのSuites(命令群)の移り変わりについては割とチェックしてきたのですが、Digital Hub Scriptingについてはちょっと自信がありません。

手元の稼働状態にあるマシンで一番古いのはOS X 10.7.5の環境で、これをチェックしたところ、Digital Hub Scripting.osaxは存在していました。

バージョン1.7です。

macOS 13.6の環境でチェックしてみたところ、

あいかわらずバージョン1.7でした。もはや、初期のMac OS Xの環境については起動可能なものがない(か、確認に時間がかかる)ため、多分このような感じなのでは? というところでしょうか。OS X 10.6.8については未確認ですが、おそらく10.6.8の段階でDigital Hub Scripting.osaxは収録されていたことでしょう。

こんなところではないかと。もはや、考古学の領域ですが、勘違いで間違っていた部分を修正できたことは喜ばしいことです。ただ、この情報はほとんど誰も追いかけていないようなので、間違っていても怒られない気配が濃厚ではあります。

Posted in Books Bug | Tagged 13.0savvy | Leave a comment

ファイルサイズの取得(symbolic link解消あり)

Posted on 9月 15, 2023 by Takaaki Naganoya

指定のPOSIX pathに存在するファイルの大きさ(ファイルサイズ)を取得するAppleScriptです。指定パスがSymbolic Linkである場合に備えて、パスの実体を求めるようにしています。

/System/Library/Frameworksフォルダ以下のFrameworkに対してbridgingsupportファイルの存在確認、およびファイルサイズの取得を行う、書籍の素材作成用のツールScriptを作ったときの、ファイルサイズ取得部分の部品です。

こういう資料は作るのに手間暇がかかるので、できるかぎりScriptから生成できるようにしています。この部分についていえば、OSのバージョンアップがあっても、作り直すのは簡単です。

AppleScript名:ファイルサイズの取得(symbolic link解消あり).scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/09/14
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

set aPath to "/System/Library/Frameworks/WebKit.framework"
set bPath to current application’s NSString’s stringWithString:(aPath)
set cPath to bPath’s stringByResolvingSymlinksInPath() as string

set dPath to cPath & "/Versions/A/Resources/BridgeSupport/WebKit.arm64e.bridgesupport"
set aFM to current application’s NSFileManager’s defaultManager()
set anAttr to aFM’s attributesOfItemAtPath:(dPath) |error|:(missing value)
set sRes to anAttr’s fileSize()
–> 57225

★Click Here to Open This Script 

Posted in file File path | Tagged 12.0savvy 13.0savvy | Leave a comment

Finder上で選択中のPDFのページ数を加算

Posted on 9月 14, 2023 by Takaaki Naganoya

Finder上で選択中のPDFのページ数を合計してダイアログ表示するAppleScriptです。ずいぶん前に作っておいたScriptのアップデート版です。

以前に作っておいたものは、BridgePlus Script Libraryを必要としていたために、ランタイム環境がScript DebuggerもしくはSDから書き出した拡張アプレットに限られていました。

これはこれで動作して便利なのですが、macOSが提供しているさまざまなランタイム環境およびサードパーティのソフトウェアが提供するランタイム環境では、このままでは動作しませんでした。BridgePlus依存部分を別のScriptに置き換えることで、より広範なランタイム環境で動作するようになるわけです。

今回置き換えたのは、指定パスのファイルからUTIを求める処理。割と、さまざまな機能を用いた部品を用意してあったので、入れ替えるだけで済みました。

本Scriptでは、Finderで選択中のファイルのUTIをすべて求め、指定のUTI(com.adobe.pdf)に該当するかどうかをチェックしています。今回のような処理では、拡張子のチェックだけで済みそうな話ですが、「画像全般」(public.image)を指定しておけば、PNGだろうがJPEGだろうが画像ならなんでもピックアップできるので、そうした処理のために用意しておいたものです。

本ScriptはPDFのページカウントなのでPDFKitの機能を利用していますが、メタデータにページ数が書いてある書類であれば、メタデータ経由で取得してもよいでしょう。最終的には、実際に書類をオープンして数えてもいいわけで。


▲Finder上でカウント対象のPDFを選択


▲macOS標準搭載のスクリプトメニューから実行


▲Finderで選択していたPDFのページ数合計を表示。コピペできるようにしてある

合計ページ数を計算したかったので素朴な表示を行なっていますが、表インタフェースでそれぞれのPDFのファイル名とページ数を一緒に表示してもいいかもしれません。

AppleScript名:Finder上で選択中のPDFのページ数を加算.scptd
— Created 2018-06-26 by Takaaki Naganoya
— Modified 2023-09-13 by Takaaki Naganoya
— 2018-2023 Piyomaru Software
use AppleScript version "2.8"
use scripting additions
use framework "Foundation"
use framework "PDFKit" –macOS 12 or later

property |NSURL| : a reference to current application’s |NSURL|
property NSArray : a reference to current application’s NSArray
property NSString : a reference to current application’s NSString
property NSPredicate : a reference to current application’s NSPredicate
property PDFDocument : a reference to current application’s PDFDocument
property NSSortDescriptor : a reference to current application’s NSSortDescriptor
property NSURLTypeIdentifierKey : a reference to current application’s NSURLTypeIdentifierKey
property NSRegularExpressionSearch : a reference to current application’s NSRegularExpressionSearch

–set inFiles to (choose file of type {"pdf"} with prompt "Choose your PDF files:" with multiple selections allowed)
tell application "Finder"
  set inFiles to selection as alias list
end tell

if inFiles = {} then
  display dialog "No PDF Selection on Finder…" with icon 1
  
return
end if

–指定のAlias listのうちPDFのみ抽出
set filRes1 to filterAliasListByUTI(inFiles, "com.adobe.pdf") of me

set totalP to 0

repeat with i in filRes1
  set tmpCount to pdfPageCount(contents of i) of me
  
if tmpCount > 0 then
    set totalP to totalP + tmpCount
  end if
end repeat

display dialog "Total Pages:" default answer (totalP as string) with icon 1

–指定PDFのページ数をかぞえる(10.9対応。普通にPDFpageから取得)
–返り値:PDFファイルのページ数(整数値)
on pdfPageCount(aFile)
  set theURL to |NSURL|’s fileURLWithPath:aFile
  
set aPDFdoc to PDFDocument’s alloc()’s initWithURL:theURL
  
set aRes to aPDFdoc’s pageCount()
  
return aRes as integer
end pdfPageCount

–Alias listから指定UTIに含まれるものをPOSIX pathのリストで返す
on filterAliasListByUTI(aList, targUTI)
  set newList to {}
  
repeat with i in aList
    set j to POSIX path of i
    
set tmpUTI to my retUTIfromPath(j)
    
set utiRes to my filterUTIList({tmpUTI}, targUTI)
    
if utiRes is not equal to {} then
      set the end of newList to j
    end if
  end repeat
  
return newList
end filterAliasListByUTI

–指定のPOSIX pathのファイルのUTIを求める
on retUTIfromPath(aPOSIXPath)
  set aURL to |NSURL|’s fileURLWithPath:aPOSIXPath
  
set {theResult, theValue} to aURL’s getResourceValue:(reference) forKey:NSURLTypeIdentifierKey |error|:(missing value)
  
  
if theResult = true then
    return theValue as string
  else
    return theResult
  end if
end retUTIfromPath

–UTIリストが指定UTIに含まれているかどうか演算を行う
on filterUTIList(aUTIList, aUTIstr)
  set anArray to NSArray’s arrayWithArray:aUTIList
  
set aPred to NSPredicate’s predicateWithFormat_("SELF UTI-CONFORMS-TO %@", aUTIstr)
  
set bRes to (anArray’s filteredArrayUsingPredicate:aPred) as list
  
return bRes
end filterUTIList

–リストに入れたレコードを、指定の属性ラベルの値でソート
on sortRecListByLabel(aRecList as list, aLabelStr as string, ascendF as boolean)
  set aArray to NSArray’s arrayWithArray:aRecList
  
set sortDesc to NSSortDescriptor’s alloc()’s initWithKey:aLabelStr ascending:ascendF
  
–set sortDescArray to current application’s NSArray’s arrayWithObjects:sortDesc–macOS 11でクラッシュ
  
set sortedArray to aArray’s sortedArrayUsingDescriptors:{sortDesc}
  
return sortedArray
end sortRecListByLabel

★Click Here to Open This Script 

Posted in file PDF | Tagged 12.0savvy 13.0savvy | Leave a comment

Voice Character IDと音程、速度、音量を指定してテキスト読み上げ

Posted on 8月 28, 2023 by Takaaki Naganoya

AVSpeechSynthesizerを呼び出して、指定文字列を読み上げる(Text to Speech)AppleScriptです。

AppleScript標準装備のsayコマンドと比べて、声の高さや読み上げ速度の設定範囲が広いようで、未知の読み上げ音声が聞こえます。

Siriの音声キャラクタはまだ指定できないようですが、次のOSぐらいでできたりするものでしょうか? 

音声レンダリングした内容をファイルに書き込む方法が分かれば、さらにいろいろできそうです。

AppleScript名:Voice Character IDと音程、速度、音量を指定して読み上げ.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/08/28
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use framework "AVFoundation"
use scripting additions

set aSynth to current application’s AVSpeechSynthesizer’s alloc()’s init()
set aUtte to current application’s AVSpeechUtterance’s alloc()’s initWithString:"こんにちは。私の名前はおとやです。"
aUtte’s setVoice:(current application’s AVSpeechSynthesisVoice’s voiceWithIdentifier:"com.apple.voice.enhanced.ja-JP.Otoya")
–aUtte’s setVoice:(current application’s AVSpeechSynthesisVoice’s voiceWithIdentifier:"com.apple.voice.compact.ja-JP.Otoya")

(aUtte’s setRate:(0.6 as real)) –0.0から1.0。デフォルト 0.5 【速度】
(
aUtte’s setPitchMultiplier:(1.8 as real)) –0.5から2.0。デフォルト1.0 【音程】
(
aUtte’s setVolume:(1.0 as real)) –0.0から1.0。デフォルト1.0 【音量】

(aSynth’s speakUtterance:(aUtte))

★Click Here to Open This Script 

Posted in Sound Text | Tagged 12.0savvy 13.0savvy AVSpeechSynthesisVoice AVSpeechSynthesizer AVSpeechUtterance | Leave a comment

新発売:Cocoa Scripting Course #6, PDFKit

Posted on 8月 22, 2023 by Takaaki Naganoya

Piymaru Softwareによる電子書籍の83冊目、「Cocoa Scripting Course #6, PDFKit」を発売しました。PDF560ページ+サンプルScript Zipアーカイブで構成されています。

→ 販売ページ

PDF処理は、Cocoa Scriptingの1つの価値ある到達点です。この処理が行いたいからCocoaの呼び出しについて苦労を重ねてきたと言えます。機械学習やREST API呼び出し、配列からの高速なデータ抽出など、Cocoa Scriptingの「おいしい用途」は星の数ほどありますが、PDF処理は間違いなくその中でもトップランクの攻略目標のうちの1つです。

日常的にPDFを扱っているScripterなら、Cocoa Scriptingによって得られるメリットが膨大なものであることをもれなく間違いなくいかんなく実感できることでしょう。

1章 入門編
2章 実践編
3章 PDFKit編

PDFKitの位置付けと役割
 用途別のフレームワークを知ろう
 PDFKit内の主要クラス
 PDFKit+AppleScriptのつかいどころ
 PDFKit+AppleScriptの注意点
 PDFKit.frameworkの利用宣言文
 (参考資料)PDFの座標系

PDFDocument Basic Samples
PDFPage Basic Samples
PDFOutline Basic Samples
PDFAnnotation Basic Samples

4章 PDF処理 基礎編

PDFの処理の流れ
 AppleScript+PDFKitでよく使う基礎的な処理
 AppleScript+PDFKitの基礎的な処理手順
 AppleScript+PDFKitでよく使う基礎的な処理の手順

PDFからの情報取得
 PDFのサイズをPointで取得
 PDFから各種情報をNSDictionaryで取得
 PDFから各種情報を文字列で取得

PDFページカウント
 PDFのページカウント(PDFDocument)
 PDFのページカウント(Metadata Lib経由)

PDF本文テキスト抽出
 PDFの全ページのテキストを抽出
 PDFのテキストをページ単位で抽出

PDFを回転
 PDFを回転させて新規保存

PDFを印刷
 PDFを印刷

RTFをPDFに変換
 RTFをPDFに変換

PDFからのテキスト検索
 PDFテキストからの指定キーワード検索

ページ単位でPDF分割
 ページ単位でPDF分割

複数PDF結合
 choose fileコマンドで選択した複数のPDFを結合

PDF→他形式画像変換
 ページ単位でJPEG画像に変換

画像連結してPDF作成
 フォルダ内のJPEG画像を新規PDFに連結
 指定フォルダ下のすべての画像を新規PDFに連結
 フォルダ内のJPEG画像を既存のPDFに連結

Multi Page TIFFからPDFへの変換
 Multi Page TIFFからPDFへの変換

アラートダイアログでPDFを表示
 アラートダイアログ+WkWebViewでPDFを表示
 アラートダイアログ+PDFViewでPDFを表示

5章 PDF処理 上級編

PDFのパスワード、暗号化設定
 PDFのアクセス権とパスワード
 パスワード設定をチェック
 設定されているパーミッションを取得
 PDFにパスワードを設定(1/2)
 PDFにパスワードを設定(2/2)
 PDFのパスワードを解除

PDFの空白ページ検出
 PDFから空白ページを削除(1/3)
 PDFから空白ページを削除(2/3)
 PDFから空白ページを削除(3/3)

PDFフォーム入力
 PDFフォームにテキスト入力して別名保存(1/2)
 PDFフォームにテキスト入力して別名保存(2/2)
 PDFフォームにチェックボックス入力(1/2)
 PDFフォームにチェックボックス入力(2/2)

Quartzフィルタ
 Quartzフィルタとは?
 QuartzFilter出力例一覧
 Quartzフィルタの一覧を出力
 白黒のQuartzフィルタをかけて出力
 ブルートーンのQuartzフィルタをかけて出力
 PDFX-3のQuartzフィルタをかけて出力
 グレートーンのQuartzフィルタをかけて出力
 明度低下のQuartzフィルタをかけて出力
 明度上昇のQuartzフィルタをかけて出力
 ファイルサイズ縮小のQuartzフィルタをかけて出力
 セピアトーンのQuartzフィルタをかけて出力

PDFアノテーションを取得、追加、書き換え、削除
 アノテーションについて
 アノテーションを取得
 サークル・アノテーションを追加
 スクウェア・アノテーションを追加
 ライン・アノテーションを追加
 テキスト・アノテーションを追加
 URLリンク・アノテーションを追加(1/2)
 URLリンク・アノテーションを追加(2/2)
 指定語群にハイライトを追加(1/2)
 指定語群にハイライトを追加(2/2)
 指定語群にアンダーラインを追加(1/2)
 指定語群にアンダーラインを追加(2/2)
 指定語群に打ち消し線を追加(1/2)
 指定語群に打ち消し線を追加(2/2)
 PDFからすべてのアノテーションを削除

PDFのリンク抽出、リンク置換
PDFのリンク先は?
リンクの各種情報を取得(1/2)
リンクの各種情報を取得(2/2)
リンク・アノテーションからURLを抽出
URLリンク・アノテーションを追加(1/2)
URLリンク・アノテーションを追加(2/2)
書類内リンク・アノテーションを追加(1/2)
書類内リンク・アノテーションを追加(2/2)
リンクアノテーションのURLを置換

PDFのOCR処理(OCRテキスト埋め込み)
 PDFのOCR処理(1/3)
 PDFのOCR処理(2/3)
 PDFのOCR処理(3/3)

PDFのしおり(TOC)を取得、追加、削除
 TOCの題名と階層が悩ましい(1/2)
 TOCの題名と階層が悩ましい(2/2)
 指定PDFのTOCを取得してレコード化(1/2)
 指定PDFのTOCを取得してレコード化(2/2)
 ノンブルだけのフラットなTOCを付加(1/2)
 ノンブルだけのフラットなTOCを付加(2/2)
 Recordデータから階層TOCを付加(1/3)
 Recordデータから階層TOCを付加(2/3)
 Recordデータから階層TOCを付加(3/3)
 Numbersの表データから階層TOCを付加(1/4)
 Numbersの表データから階層TOCを付加(2/4)
 Numbersの表データから階層TOCを付加(3/4)
 Numbersの表データから階層TOCを付加(4/4)
 指定PDFのTOCを削除

添付サンプルScript紹介

サンプルScript集

資料編

Posted in Books news PRODUCTS | Tagged 12.0savvy 13.0savvy PDFAnnotation PDFDocument PDFOutline PDFPage | Leave a comment

Skim Notesのじっけん

Posted on 8月 18, 2023 by Takaaki Naganoya

目下、「Cocoa Scripting Course #6 PDFKit」の仕上げ作業中ですが、懸案事項がありました。

PDFに対してコメント、注釈的なもの(PDFAnnotation)をつけられるようになっていますが、各アプリケーションで管理方法が微妙に異なっており、互換性がありません。

Adobe Acrobatが付けたアノテーション → Skimで表示できない、プレビュー.appで表示できる
Skimが付けたアノテーション → Adobe Acrobat、プレビュー.appで表示できない
プレビュー.appが付けたアノテーション → Adobe Acrobat、Skimで表示できる


▲Skim上でPDFに対して各種アノテーションを付加した状態


▲Skim上でPDFに各種アノテーションを付加したものをPreview.appで表示。何も表示されない


▲Skim上でPDFに各種アノテーションを付加したものをAdobe Acrobatで表示。こちらも何も表示されない

SkimとAcrobatのアノテーションの互換性がナニでアレでありますが、一応プレビュー.appとSkimがあればなんとかなる感じです。

さて、Skimでアノテーションを付けるとSkim同士でしかアノテーションを表示できない状態になってしまい、かつ、AppleScriptからPDFKitを操作しても読めないので困っていました(SkimのGUIアプリケーション経由で取得できないこともなさそう)。

Skimのアノテーションを読むために、Skim本体とは別にSkimNotes.frameworkとSkimNotesBase.frameworkが提供されています。Skim.appとは別にインストールする必要があります。インストール先は~/Library/Frameworksです。

コード署名されていないので、Script Debugger上でこれらのFrameworkの機能を呼び出そうとすると、署名されていない旨の警告が表示されますが、システム設定.app>セキュリティとプライバシーで認証できます。これら2つのFramrworkの両方とも認証しておく必要があります。

テストデータとして、Skim.app上でノートアノテーションをPDFに追記して保存。これに対して、AppleScriptからアクセスできるか試してみました。

結論からいえば、AppleScriptからアクセスできるわけですが、互換性を持たせるような何かがあってもいいような気がするところです。Adobe Acrobatでアノテーションを記載したPDFを、Skimで見られるように修正するとか。Skimで記入したアノテーションを他のアプリケーションでも見られるように変換するとか。

AppleScript名:Skim Notesのじっけん.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/08/17
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.8"
use framework "Foundation"
use framework "PDFKit"
use framework "SkimNotes"
use framework "SkimNotesBase"
use scripting additions

set aPOSIX to POSIX path of (choose file of type {"com.adobe.pdf"})
set aURL to (current application’s |NSURL|’s fileURLWithPath:aPOSIX)

set aPDFdoc to current application’s PDFDocument’s alloc()’s initWithURL:aURL readSkimNotes:true
set pCount to aPDFdoc’s pageCount()

repeat with ii from 0 to (pCount – 1)
  log ii –Page Count
  
  
set firstPage to (aPDFdoc’s pageAtIndex:ii)
  
–>  (PDFPage) PDFPage, label 1
  
  
set anoList to (firstPage’s annotations()) as list
  
if anoList is not equal to {} then
    repeat with i in anoList
      set j to contents of i
      
log j
      
(*(SKNPDFAnnotationNote) Type: ’/Text’, Bounds: (320, 737) [16, 16]\n*)
      
      
set aType to (j’s type()) as string
      
log aType
      
(*Note*)
      
      
if aType = "Note" then
        set cVal to j’s |contents|() as string
        
log cVal
        
(*Skim Noteのタイトルだよ Skim Noteの本文だよ\n\n*)
        
        
set cVal to j’s iconType()
        
log cVal
        
(*0*)
        
        
set dVal to j’s isSkimNote() as boolean
        
log dVal
        
(*true*)
        
        
if dVal = true then
          set eVal to j’s |string|()
          
log eVal
          
(*(NSString) "Skim Noteのタイトルだよ"*)
          
          
set fVal to j’s SkimNoteProperties()
          
(*(NSDictionary) {bounds:"{{308, 732}, {16, 16}}", color:(NSColorSpaceColor) sRGB IEC61966-2.1 colorspace 1 1 0.5 1, userName:"Takaaki Naganoya2", modificationDate:(NSDate) "2023-08-17 14:38:39 +0000", image:<NSImage 0x6000067d32a0 Size={1920, 1200} RepProvider=<NSImageArrayRepProvider: 0x6000015034a0, reps:(\n "NSBitmapImageRep 0x600003eb85b0 Size={1920, 1200} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=1920×1200 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x600001089360"\n)>>, contents:"Skim Noteのタイトルだよ", text:(NSConcreteAttributedString) Skim Note{\n NSFont = ""Helvetica 12.00 pt. P [] (0x11f597610) fobj=0x139642430, spc=3.33"";\n NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ’(null)’";\n}の本文だよ\n\n{\n NSFont = ""HiraginoSans-W3 12.00 pt. P [] (0x11f597610) fobj=0x11f5277a0, spc=4.00"";\n NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ’(null)’";\n}, type:"Note", pageIndex:0, iconType:0}*)
          
          
set anImage to fVal’s image
          
log anImage
          
(*<NSImage 0x6000067cf700 Size={1920, 1200} RepProvider=<NSImageArrayRepProvider: 0x6000015182c0, reps:(\n "NSBitmapImageRep 0x600003effb10 Size={1920, 1200} ColorSpace=(not yet loaded) BPS=8 BPP=(not yet loaded) Pixels=1920×1200 Alpha=YES Planar=NO Format=(not yet loaded) CurrentBacking=nil (faulting) CGImageSource=0x60000105fa20"\n)>>*)
          
          
set colRes to fVal’s |color|
          
log colRes
          
(*(NSColorSpaceColor) sRGB IEC61966-2.1 colorspace 1 1 0.5 1*)
          
          
set tRes to fVal’s |text|
          
log tRes
          
(*(NSConcreteAttributedString) Skim Note{\n NSFont = ""Helvetica 12.00 pt. P [] (0x1296dd6e0) fobj=0x139642430, spc=3.33"";\n NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ’(null)’";\n}の本文だよ\n\n{\n NSFont = ""HiraginoSans-W3 12.00 pt. P [] (0x1296dd6e0) fobj=0x11f5277a0, spc=4.00"";\n NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (\n), BaseWritingDirection -1, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (\n) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ’(null)’";\n}*)
          
          
set sBounds to fVal’s |bounds|
          
log sBounds
          
(*(NSString) "{{308, 732}, {16, 16}}"*)
          
          
set uName to fVal’s userName
          
log uName
          
(*(NSString) "Takaaki Naganoya2"*)
          
          
set modRes to fVal’s modificationDate
          
log modRes
          
(*(NSDate) "2023-08-17 14:38:39 +0000"*)
          
        end if
      end if
    end repeat
  end if
  
end repeat

★Click Here to Open This Script 

Posted in PDF | Tagged 13.0savvy Skim | Leave a comment

Excelの書類上に置かれているpictureが置かれているセルのアドレスを推定する v2

Posted on 8月 9, 2023 by Takaaki Naganoya

Excelのワークシート上にドラッグ&ドロップして配置された画像のセルのアドレスを推定するAppleScriptの強化版です。

このぐらい作り込んでおけば実用性のある部品になることでしょう。Microsoft Excel 16.76を対象に検証を行なっています。テストは1つのExcel書類上に1つだけ画像を配置(Finderからドラッグ&ドロップで配置)した状態、1つのセルの上に乗っているように見える状態に大きさを調整して実行しました。

まず、大前提でpictureのID(1から始まる通し番号)、pictureの始点座標が存在するExcel上のセルのrow(行)とcolumn(列)。これはあらかじめ各Pictureの始点座標をもとにあらかじめ計算しておいたものを使います。

本Scriptは、この「始点座標から存在するセルを計算」する処理の後処理として、実際に画像が重なっているセルを重なっている部分の面積をもとに最大の面積のものを「配置されているセル」として計算で推定します。

この処理には前提条件があって、複数のセルにまたがりすぎているような(数十のセルにまたがってpictureが配置されている)場合には計算そのものが無意味です。「1セルに1画像ぐらい」の調子で配置されていないと、こうした処理を行なっても無駄になってしまいます。

本Scriptでは、Excelワークシートの対象のpictureのID、pictureの始点座標から求めたセルのrow(行)とcolumn(列)を与えて呼び出します。すると、始点セルを基準に3×3のセルの矩形エリア(NSRect)を求め、pictureの矩形(NSRect)との重なっている面積を計算。もっとも面積が大きいものを対象セルとしてrow, columnを返します。

こうしたScriptを作ってほうがよいと考えた理由は、このExcelシート上に貼り付けた画像に対してさまざまな文字データが隣のセルに入力され、セル上のデータと画像を関連づけてデータ取得するような処理を考えたときに必要と考えたためです。

AppleScript名:pictureが置かれているセルのアドレスを推定する v2.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/08/07
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—
use AppleScript
use scripting additions
use framework "Foundation"

set targRow to 22
set targCol to 2
set targPictureID to 1

set tCell to getPictureLocatedCellRowColByItsPosition(targRow, targCol, targPictureID) of me
–> {rowNum:23, columnNum:2}

–ループで指定セルを左上とした3×3の範囲のセルから、指定のPictureと重なっている面積が最も大きいものを返す
on getPictureLocatedCellRowColByItsPosition(targRow as integer, targCol as integer, targPictureID as integer)
  
  
–Picture 1のNSRectを求める
  
set pRect to getAPictureRectByID(targPictureID) of me
  
  
set tmpList to {}
  
  
–始点座標から3×3の範囲のセルとPictureの重なる面積を計算
  
repeat with x from 0 to 2
    repeat with y from 0 to 2
      
      
set tmpRow to (targRow + y)
      
set tmpCol to (targCol + x)
      
      
set tmpRect to retExcelCellRect(tmpRow, tmpCol) of me
      
      
–指定Pictureと指定Cellの共通部分の矩形座標を計算
      
set a1Res to (current application’s NSIntersectionRect(tmpRect, pRect)) as {record, list}
      
      
–指定Pictureと指定Cellの共通部分の面積を計算
      
set a1Area to calcAnArea(a1Res) of me
      
if a1Area > 0 then
        set the end of tmpList to {columnNum:tmpCol, rowNum:tmpRow, interAreaWithPict:a1Area}
      end if
      
    end repeat
  end repeat
  
  
–面積で降順ソート
  
set zList to (sortRecListByLabel(tmpList, {"interAreaWithPict"}, {false}) of me) as list
  
–> {{columnNum:2, rowNum:23, interAreaWithPict:4973.377807617188}, {columnNum:2, rowNum:24, interAreaWithPict:747.665495456778}, {columnNum:2, rowNum:22, interAreaWithPict:333.296168677043}}
  
  
set resCell to first item of zList
  
set resCol to columnNum of resCell
  
set resRow to rowNum of resCell
  
  
return {rowNum:resRow, columnNum:resCol}
end getPictureLocatedCellRowColByItsPosition

–IDで指定したPictureのNSRectを返す
on getAPictureRectByID(anID as integer)
  tell application "Microsoft Excel"
    tell active workbook
      tell active sheet
        set anImage to picture anID
        
        
set tmpX to left position of anImage
        
set tmpY to top of anImage
        
set tmpW to width of anImage
        
set tmpH to height of anImage
      end tell
    end tell
  end tell
  
  
set aZRect to current application’s NSMakeRect(tmpX, tmpY, tmpW, tmpH)
  
return aZRect
end getAPictureRectByID

–NSRectの面積を計算する
on calcAnArea(aRect)
  if class of aRect = list then
    set xWidth to (item 1 of item 2 of aRect)
    
set yHeight to (item 2 of item 2 of aRect)
  else
    set xWidth to (aRect’s |size|’s width)
    
set yHeight to (aRect’s |size|’s height)
  end if
  
  
set anArea to xWidth * yHeight
  
return anArea
end calcAnArea

–指定Row, ColumnのCellのNSRectを返す
on retExcelCellRect(y as integer, x as integer)
  tell application "Microsoft Excel"
    tell active workbook
      tell active sheet
        tell row y
          tell cell x
            set xMin0 to left position
            
set yMin0 to top
            
set xWidth0 to width
            
set yHeight0 to height
          end tell
        end tell
      end tell
    end tell
  end tell
  
  
set a1Rect to current application’s NSMakeRect(xMin0, yMin0, xWidth0, yHeight0)
  
return a1Rect
end retExcelCellRect

–リストに入れたレコードを、指定の属性ラベルの値でソート
on sortRecListByLabel(aRecList as list, aLabelStr as list, ascendF as list)
  set aArray to current application’s NSArray’s arrayWithArray:aRecList
  
  
set aCount to length of aLabelStr
  
set sortDescArray to current application’s NSMutableArray’s new()
  
repeat with i from 1 to aCount
    set aLabel to (item i of aLabelStr)
    
set aKey to (item i of ascendF)
    
set sortDesc to (current application’s NSSortDescriptor’s alloc()’s initWithKey:aLabel ascending:aKey)
    (
sortDescArray’s addObject:sortDesc)
  end repeat
  
  
return (aArray’s sortedArrayUsingDescriptors:sortDescArray)
end sortRecListByLabel

★Click Here to Open This Script 

Posted in rectangle | Tagged 13.0savvy Excel | 1 Comment

Excelの書類上に置かれているpictureのセルのアドレスを推定する

Posted on 8月 7, 2023 by Takaaki Naganoya

Excelのワークシート上にドラッグ&ドロップして配置された画像のセルのアドレスを推定するAppleScriptの試作品です。

ただし、pictureオブジェクトは単にExcel書類上に重ね合わせて配置されている「異物」であり、どこかのセルに置かれているわけではありません。オブジェクトからpropertiesを取得しても、セルのアドレスを取得できたりはしません。ワークシート左上を原点とする座標値が取得できるだけです。

ただ、pictureの配置座標を取得して、その座標からセルを求める処理を行ったとしても(やりました)、配置座標と実際に置かれているセルは異なります。

実際に、Excelワークシート上に配置されている画像を個別に書き出す処理(リサイズして高解像度化する処理つき)を書いて動かしてみましたが、書き出したファイル名にセルのアドレスを反映させたら使いやすいのではないかと考え、解決策を試してみました。

上の画面キャプチャでいえば、R22C2のセルにpicture 1が存在している(始点座標が存在している)わけなのですが、実際に目で見た感じではR23C2に存在している(ユーザーがそのように作業を行った)ものと推定されます。この画像をファイル書き出しする際に、R22C2というファイル名をつけてしまっては、後で整理する際に「ナニコレ?」という話になってしまいます。

そこで、複数のセルにまたがってpictureオブジェクトの矩形領域と、それぞれ重なっているセルの矩形領域の共通部分を求め、面積を計算。共通面積が最も大きいものを採用するための試作品を作ってみた次第です。

AppleScript名:pictureが置かれているセルのアドレスを推定する.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/08/07
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

use AppleScript
use scripting additions
use framework "Foundation"

set aRect to retExcelCellRect(22, 2) of me
set bRect to retExcelCellRect(23, 2) of me

tell application "Microsoft Excel"
  tell active workbook
    tell active sheet
      set anImage to picture 1
      
      
set tmpX to left position of anImage
      
set tmpY to top of anImage
      
set tmpW to width of anImage
      
set tmpH to height of anImage
    end tell
  end tell
end tell

set aZRect to current application’s NSMakeRect(tmpX, tmpY, tmpW, tmpH)

–共通部分の矩形座標を計算
set a1Res to (current application’s NSIntersectionRect(aRect, aZRect)) as {record, list}
set b1Res to (current application’s NSIntersectionRect(bRect, aZRect)) as {record, list}

–共通部分の面積を計算
set a1Area to calcAnArea(a1Res) of me
set b1Area to calcAnArea(b1Res) of me

–大小判定
if a1Area > b1Area then
  return "a is larger"
else
  return "b is larger"
end if

–NSRectの面積を計算する
on calcAnArea(aRect)
  if class of aRect = list then
    set xWidth to (item 1 of item 2 of aRect)
    
set yHeight to (item 2 of item 2 of aRect)
  else
    set xWidth to (aRect’s |size|’s width)
    
set yHeight to (aRect’s |size|’s height)
  end if
  
  
set anArea to xWidth * yHeight
  
return anArea
end calcAnArea

on retExcelCellRect(y, x)
  tell application "Microsoft Excel"
    tell active workbook
      tell active sheet
        tell row y
          tell cell x
            set xMin0 to left position
            
set yMin0 to top
            
set xWidth0 to width
            
set yHeight0 to height
          end tell
        end tell
      end tell
    end tell
  end tell
  
  
set a1Rect to current application’s NSMakeRect(xMin0, yMin0, xWidth0, yHeight0)
  
return a1Rect
end retExcelCellRect

★Click Here to Open This Script 

Posted in rectangle | Tagged 13.0savvy Excel | Leave a comment

マンデルブロ集合を文字で描画してRTFとして組み立ててテキストエディットでオープン

Posted on 8月 6, 2023 by Takaaki Naganoya

マンデルブロ集合を文字で組み立てて、デスクトップフォルダにRTF形式で保存して、テキストエディットでオープンして表示するAppleScriptです。

Courier Newはどの環境にも入っているフォントだと思っていますが、ない場合には別の等幅フォントのPostScript名に変更してください。また、フォントサイズや描画色を変更してみるといいかもしれません。

ちなみに、実用性はまっっっっったくありません。昔は計算に数分かかったのに、いまだとインタプリタ型の言語で動かしても1秒以下なんだ、へーという納得ができる程度です。

AppleScript名:マンデルブロ集合を描画してRTFとして組み立ててテキストエディットでオープン.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/08/06
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—
use AppleScript
use framework "Foundation"
use framework "AppKit"
use scripting additions

property NSFont : a reference to current application’s NSFont
property NSUUID : a reference to current application’s NSUUID
property NSColor : a reference to current application’s NSColor
property NSString : a reference to current application’s NSString
property NSDictionary : a reference to current application’s NSDictionary
property NSLiteralSearch : a reference to current application’s NSLiteralSearch
property NSMutableArray : a reference to current application’s NSMutableArray
property NSMutableDictionary : a reference to current application’s NSMutableDictionary
property NSFontAttributeName : a reference to current application’s NSFontAttributeName
property NSMutableAttributedString : a reference to current application’s NSMutableAttributedString
property NSForegroundColorAttributeName : a reference to current application’s NSForegroundColorAttributeName
property NSDocumentTypeDocumentAttribute : a reference to current application’s NSDocumentTypeDocumentAttribute

set outStr to generateMandel() of me
set anAssrStr to makeRTFfromParameters(outStr, "CourierNewPSMT", 12) of me

–結果のRTFをデスクトップ上に書き出す。ファイル名はUUID.rtf
set thePath to (POSIX path of (path to desktop)) & (do shell script "uuidgen") & ".rtf"
set aRes to my saveStyledTextAsRTF(thePath, anAssrStr)

set targAlias to (POSIX file (thePath as string)) as alias

tell application "TextEdit"
  activate
  
open targAlias
end tell

–スタイル付きテキストを指定パス(POSIX path)にRTFで書き出し
on saveStyledTextAsRTF(targPath, aStyledString)
  set targPathNSString to NSString’s stringWithString:targPath
  
set bstyledLength to aStyledString’s |string|()’s |length|()
  
set bDict to NSDictionary’s dictionaryWithObject:"NSRTFTextDocumentType" forKey:(NSDocumentTypeDocumentAttribute)
  
set bRTF to aStyledString’s RTFFromRange:(current application’s NSMakeRange(0, bstyledLength)) documentAttributes:bDict
  
return (bRTF’s writeToFile:targPath atomically:true) as boolean
end saveStyledTextAsRTF

–書式つきテキストを組み立てる
on makeRTFfromParameters(aStr as string, aFontName as string, aFontSize as real)
  set aVal1 to NSFont’s fontWithName:aFontName |size|:aFontSize
  
set aKey1 to (current application’s NSFontAttributeName)
  
  
set aVal2 to NSColor’s cyanColor()
  
set aKey2 to (current application’s NSForegroundColorAttributeName)
  
  
set aVal3 to 0.0
  
set akey3 to (current application’s NSKernAttributeName)
  
  
set keyList to {aKey1, aKey2, akey3}
  
set valList to {aVal1, aVal2, aVal3}
  
set attrsDictionary to NSMutableDictionary’s dictionaryWithObjects:valList forKeys:keyList
  
  
set attrStr to NSMutableAttributedString’s alloc()’s initWithString:aStr attributes:attrsDictionary
  
return attrStr
end makeRTFfromParameters

–マンデルブロ集合を文字で描画して返す
on generateMandel()
  set outStr to ""
  
  
repeat with y from -12 to 12 by 1
    
    
repeat with x from -39 to 39 by 1
      
      
set ca to x * 0.0458
      
set cb to y * 0.08333
      
      
set a to ca
      
set b to cb
      
      
repeat with i from 0 to 15 by 1
        set t to (a * a) – (b * b) + ca
        
set b to (2 * a * b) + cb
        
        
set a to t
        
        
if ((a * a) + (b * b)) > 4 then exit repeat
      end repeat
      
      
      
if ((a * a) + (b * b)) ≤ 4 then
        set outStr to outStr & " "
      else
        if i > 9 then set i to i + 7
        
set outStr to outStr & string id (48 + i)
      end if
      
    end repeat
    
    
set outStr to outStr & return
  end repeat
  
  
return outStr
end generateMandel

★Click Here to Open This Script 

Posted in File path RTF Text | Tagged 12.0savvy 13.0savvy TextEdit | Leave a comment

PowerPointを操作するAppleScriptをScript Menuに入れて実行すると動作が完結しない問題

Posted on 8月 4, 2023 by Takaaki Naganoya

日常的に利用するAppleScriptは、macOS標準搭載のScript Menuに入れて使用しています。エンドユーザーに「Script Editor上で実行しろ」とかいうのは無茶ですし、「全部Appletに書き出してアプリケーションとして実行」とかいうのも、セキュリティ的な縛りが増えた環境においては、無茶な話です。だいたい、日常的に利用している数百本のAppleScriptを全部Appletに書き出すというのも(自動処理でできるけど)無茶な話です。

そのため、日常的に利用するAppleScriptは、個人的にScript Menuから実行していますし、Script Menuを「最終防衛線」として定義し、AppleがOSアップデートのたびに作成するバグに対して文句を言っています。Script Menu上で動かなかったら問題視しています。

さて、そこに新たな頭痛の種が舞い込んできました。ここ数日いじくりまわしているPowerPointです。

いつものように、Script Menuに操作系のScriptを入れて実行すれば、それでおしまい! というわけには行きませんでした。PowerPointの書類からTOCつきのPDFを書き出すAppleScriptを書いて、Script Menuに入れたら実行できなくなりました(途中までは実行できるのに……)。Script Editor/Script Debugger上では問題なく実行できるのに、です。

この場合、Script Menuがランタイム環境(実行環境)になるわけで、各種セキュリティ設定もScript Menuに対して行っています。AppleScript Appletを数百個自動生成できたとしても、数百個のAppletに対してすべてセキュリティ設定を行うのは現実的な話ではありません。Script Menuに対して権限設定をまとめておけたほうが便利です。

そのため、Script Menuには「オートメーション」「フルディスクアクセス」「アクセシビリティ」など考えられる一通りのセキュリティ設定が行われているわけですが、先のPowerPointを操作するAppleScriptが、Script Menu上からは実行が完了しませんでした。

どうもファイルアクセス権限に関する問題(Script Editor上から実行しても、初回はダイアログが出る)のようなのですが、この権限がScript Menuから実行すると取得できないようで…

この問題をAppleに報告すべきなのか、Microsoftに報告すべきなのか、現状だと判断がつかないところです(たらいまわしにされる予感)。

PowerPointなんか使う方が悪い、という話までありそうな、、、、

Posted in Bug | Tagged 13.0savvy PowerPoint Script Menu | 1 Comment

PowerPoint書類の各スライドのタイトルを取得

Posted on 8月 3, 2023 by Takaaki Naganoya

PowerPoint書類(presentation)の各スライドのタイトルを取得するAppleScriptです。

正確にいえば、タイトルを取得するかもしれないAppleScriptです。本Scriptの実行時にはPowerPointで何らかのPPTX書類をオープンしていることを期待しています。

PowerPointをこづき回してみると、各スライドのタイトルを保持しているプロパティとかいったものが「ない」ことに気づきます。

ではどうやって取り出すかといえば、

(1)slideのplace holderを取得する
(2)place holder内にtext frameが存在しているかを確認
(3)text frameが存在している場合には、内部にアクセスして文字を取り出す

という手順になるようです。

ただし、place holderにアクセスする都合上、

スライドのレイアウトの種類によってはplace holderが存在していないものもあるため、place holderの存在確認から行うべきかもしれません。

また、slide内に複数のplace holderが存在する場合に、どれがtitleに該当するのかを調べる必要があるとか(座標とか、文字サイズとかを頼りに推測)、いろいろと処理が破綻しそうな「例外条件」が多数存在していそうです。

AppleScript名:各slideのタイトル文字列を取得 v2.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/08/03
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

set tList to getEveryPPTSlideTItles() of me
–> {"Title", "1章", "Slide1", "Slide2", "2章", "Slide3", "Slide4"}

on getEveryPPTSlideTItles()
  set tList to {}
  
  
tell application "Microsoft PowerPoint"
    tell active presentation
      set sList to every slide
      
      
repeat with i in sList
        set j to contents of i
        
        
tell j
          
          
set plaList to every place holder
          
set aPla to contents of first item of plaList
          
set hText to (has text of text frame of aPla) as boolean
          
          
if hText = true then
            set hTextR to (content of text range of text frame of aPla) as string
          else
            set hTextR to ""
          end if
          
        end tell
        
        
set the end of tList to hTextR
      end repeat
      
      
return tList
      
    end tell
  end tell
end getEveryPPTSlideTItles

★Click Here to Open This Script 

Posted in Object control | Tagged 13.0savvy PowerPoint | Leave a comment

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

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

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (204) 14.0savvy (159) 15.0savvy (151) 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 (56) 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