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

タグ: 12.0savvy

Claris FileMaker 2023がリリースされる

Posted on 5月 23 by Takaaki Naganoya

日本国内においても、Claris FileMaker 2023および前バージョンのClaris FileMaker v19.xからのアップデータがリリースされました。「2023」と銘打っているからには、翌年には「2024」が出てくることが期待されるわけで……販売戦略的なものがいろいろ変更されることがうかがわれます。

商標その他で記述すべき名称は変わっていますが、macOS上でのプロセス名としては「FileMaker Pro」であることに変更はありません。Clarisの(技術サポート系の)Web上の表記は「FileMaker Pro 20.1」となっているようです。

なお、macOS上でのバンドルIDは「com.filemaker.client.pro12」のままで変更されていません。

アプリケーションのアイコンは変更されています。

まだ確認中ではありますが、AppleScript用語辞書も前バージョンから変更なく、書籍のアップデートもとくに行わなくてもよさそうな雰囲気であります(アイコンと画面スナップショットの都合で差し替えるか別の本にする必要があるかもしれません)。

「Claris FileMaker 2023」が製品シリーズを包括する名称で、macOS上で動作するクライアントソフトウェアについては「Claris FileMaker Pro 2023」であると認識しています。

Claris FileMaker Pro 2023がサポートするOSは、macOS 12と13。Windows 10(22H2、64bitのみ)、Windows 11(22H2、64bitのみ)。

FileMaker GoはiOS 16/iPadOS 16が動作するデバイスが稼働対象です。

(Visited 17 times, 1 visits today)
Posted in news | Tagged 12.0savvy 13.0savvy FileMaker Pro | Leave a comment

指定のアプリケーションの実行アーキテクチャを変更

Posted on 5月 3 by Takaaki Naganoya

指定のアプリケーションの実行アーキテクチャを変更するAppleScriptです。

–> Download setArchLib.scptd

Apple Silicon Mac上でアプリケーションをRosetta 2によってIntel 64バイナリのARMエミュレーション動作を行うかどうかは、Finder上の「Rosettaを利用して開く」のチェックボックスによって制御されています。

これを、外側(FinderのGUI)から操作するか、内側(何らかのOS内のサービスやメタデータ)から操作するかによって、その「やりかた」は大きく異なります。

自分は、できることなら極力GUI Scriptingを使いたくない派なので、「そういえばASからこのあたりの設定をいじくった記憶がない」と思いつつ、「内側から操作する方法はないものか」と考えていました。

さっそくGithub上でいろいろ調査してみたところ、LaunchServiceのプライベートAPIに「_LSSetArchitecturePreferenceForApplicationURL」というものがあって、これを呼ぶことで処理を実現できそうだということが判明。

処理内容は、アゴが外れそうなほど簡単なので、AppleScript(AppleScriptObjC)でも普通に書けそうな勢いでしたが、アンダースコアで始まるAPIはAppleScriptにBridgeしにくく、もともとのプロジェクトのもの(UNIXのコマンドラインから呼び出す「SetArchPrefForURL」プロジェクト)をビルドしたバイナリをScriptバンドル内に入れて、呼び出すようにしてみました。

Cocoa Frameworkのプロジェクトを作成して、AppleScriptから普通にPOSIX pathとCPUアーキテクチャを渡せば結果をbooleanで返してくるようなスタイルに書き換えようとして、途中で頓挫してしまいました。そんなに気合いを入れる内容でもないので、こんなものでいいんでしょう。

AppleScript名:setArchLib.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/05/03
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set appPath to choose file of type {"com.apple.application-bundle"}
–set archStr to "x86_64"
set archStr to "arm64"

set archRes to setArchForApp(appPath, archStr as string) of me

on setArchForApp(appPath, archStr as string)
  if archStr is not in {"x86_64", "arm64"} then error "Invalid architecture"
  
  
set exePath to POSIX path of (path to resource "SetArchPrefForURL")
  
set sRes to do shell script (quoted form of exePath) & " " & (quoted form of POSIX path of appPath) & " " & archStr
  
return (sRes = "") as boolean
end setArchForApp

★Click Here to Open This Script 

(Visited 36 times, 1 visits today)
Posted in file System | Tagged 11.0savvy 12.0savvy 13.0savvy | Leave a comment

画像をExcelのワークシート上に配置

Posted on 4月 4 by Takaaki Naganoya

Microsoft 365のExcel v16.71、Windows版とmacOS版のソースコードが共通化されたというふれ込みではあるものの、実はけっこうフォーム部分が違うし、VBのマクロエディタで日本語が記入できないとか、互換性のない関数(Mac上で動作しないENCODEURL、Switch,IFS、FILTERXML、WEBSERVICEなどの関数)の存在など、いろいろ勘弁してほしい出来です。

しばらくはNumbersだけで用が済んでいたのですが、ここのところWindows版のExcelの講座なども行っていたので、併せてmacOS版のExcelについても追加調査。細かい点のチェックを行っていました。

そんなExcelでアドインのオンラインストアからQRコード作成用アドインを探してみたところ、フリーなものは存在していないようです。

Cocoaの機能を利用すれば、割とすぐにできてしまう程度のQRコード。わざわざアドインの力を利用する必要などなかったのです。AppleScriptでQRコードを生成して、Excelのワークシートに差し込めばよいだけです。

ところが、ひさしぶりにExcelのScriptを引っ張り出してきて、昔書いた「Excelに指定の画像を配置する」Scriptを実行してみたところ、エラーで動きません。

ワークシート上にshapeを作成できるのに、そのshapeに指定パスの画像を割り当てる処理でエラーになります。

そんな時、「出来の悪いプログラマは、POSIX pathで誤魔化して実装する」という経験則が思い出されました。

目を閉じると、AppleのKeynoteで一時期行われていた、画像配置コマンドにPOSIX pathを要求していたアレな実装であるとか(あれはひどかった)、いまだにアレであり続けているAdobe Acrobat DistillerのdistillコマンドがPOSIX pathを要求する件であるとか(file pathって書いてあるのに、aliasじゃなくてPOSIX pathを要求するという地雷仕様)、枚挙にいとまがありません。

そんなわけで、普通に書いても通らなかったのでパスをPOSIX pathで与えてみたところ、見事(?)配置されました。

AppleScript名:画像をワークシート上に配置.scpt
set anImagePath to choose file
set anImagePOSIX to POSIX path of anImagePath

tell application "Microsoft Excel"
  set cwb to workbook 1
  
tell cwb
    tell worksheet 1
      set aPicShape to make new shape at the beginning
      
set width of aPicShape to 312
      
set height of aPicShape to 312
      
user picture of aPicShape picture file anImagePOSIX
    end tell
  end tell
end tell

★Click Here to Open This Script 

(Visited 33 times, 1 visits today)
Posted in Bug file File path | Tagged 11.0savvy 12.0savvy 13.0savvy Excel | Leave a comment

Keynote,Pages,Numbers v13.0がリリースされる

Posted on 4月 2 by Takaaki Naganoya

Keynote, Pages, Numbersのバージョン13.0がリリースされました。AppleScript用語辞書的な変更点はありません。

Keynote v11からずっと、新規書類を保存するとエラーになる。Full Disk Accessの権限をKeynoteに与えていてもエラーになる、という重大な問題が解消されないままである、という認識でおりました。状況はKeynote v13.0でも変わりません。

これは、Apple側が問題として認識していないのではないか? という仮説を立て、いろいろ試してみました。

まずは、v12から継続している状況についての説明。Keynoteで新規書類を保存する際に「as Keynote」という、明らかに「指定してくださいね」というオプションがAppleScript用語辞書の中にあるので、指定したくなるところですが

AppleScript名:Keynoteで書類を新規保存(A).scpt
set newFile to ((path to desktop) as string) & "newDoc1111.key"

tell application "Keynote"
  set newDoc to make new document
  
save document 1 in file newFile as Keynote
end tell

★Click Here to Open This Script 

これを指定するとエラーになります。これが、Keynote v12.0から続いており、1年以上継続している状況です。以前のバージョンで通っていた記述がエラーを出すようになった、というものです。

ふとここで、「as Keynote」というオプション指定をはずしてみると…….

AppleScript名:Keynoteで書類を新規保存(A).scpt
set newFile to ((path to desktop) as string) & "newDoc1111.key"

tell application "Keynote"
  set newDoc to make new document
  
save document 1 in file newFile
end tell

★Click Here to Open This Script 

エラーが出なくなりました!!!(^ー^;;;; ファイル保存もできました。

なんなんでしょう、これは、、、、

(Visited 29 times, 1 visits today)
Posted in Bug news | Tagged 12.0savvy 13.0savvy Keynote Numbers Pages | Leave a comment

アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3

Posted on 3月 7 by Takaaki Naganoya

アラートダイアログ上にWkWebViewを作成して、さまざまなグラフや3Dアニメーションを表示してきた「箱庭ダイアログ」の1つの到達点、「periodictable」(元素周期表)選択UIの表示デモAppleScriptです。

このデモ、macOS 10.14あたりまでは動いていたのですが、その後のmacOSのアップデートにより、表示されなくなっておりました。

いろいろ調べたところ、macOSの開発者もiOSの開発者も揃いも揃って「表示できない」と言っているのを見て、逆に何か解決策がありそうな気がしてきました。

ローカルに保存しておいた1枚ものの表示用HTML(2020/05に作成したもの)は、当時のSafariで表示できており、WkWebViewでも表示できていました。

現在、この1枚もののHTMLはSafariでもWkWebViewでも表示できないようになっています。
その一方で、three.jsのWebサイトに掲載されているperiodictableのサンプルは現行のSafariで表示でき、操作も行えます。

当初は、これを「SafariとWkWebViewの差」だと思って、WkWebViewをカスタマイズしまくらないとSafariと同等の表示が行えないのではないか? と考えていました。ただ、探しても探しても答えが見つからず、この方向で情報収集を行っても「無駄」に思えてきました。

そこでにわかに浮上してきたのが、「periodictable」や「three.js」自体がアップデートされている説、です。

WebKit(WkWebView)側のアップデート、およびCDN上のJavaScriptのライブラリのアップデートの相互作用によって表示できなくなったのではないかと、調査の方向を変えてみました。

当時のサンプルHTMLと現在のサンプルHTMLのdiffをとって、読み込むCDN上のライブラリを変更したり、追加することで現行OS上のWkWebView上でも動作するようになりました。

つまり、文字列として与えているHTMLの部分のみ変更しただけで、AppleScript部分とかWkWebViewまわりは一切手をつけていません。わかってしまえば、「なーんだ」という内容ですが、これにはなかなか対応できませんでした。

あとは、クリックした項目のURLイベントをAppleScript側で受信できればなおよいのですが、、、アプリケーションとして独立したものに変更して、AppleScript用語辞書を介して「display periodictable」みたいなコマンドでAppleScript側と値をやりとりするのがよいのかもしれません。

AppleScript名:アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2020/06/13
–  Modified on: 2023/03/07
—
–  Copyright © 2020-2023 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.7"
use framework "Foundation"
use framework "AppKit"
use framework "WebKit"
use scripting additions

property |NSURL| : a reference to current application’s |NSURL|
property NSAlert : a reference to current application’s NSAlert
property NSString : a reference to current application’s NSString
property NSButton : a reference to current application’s NSButton
property WKWebView : a reference to current application’s WKWebView
property WKUserScript : a reference to current application’s WKUserScript
property NSURLRequest : a reference to current application’s NSURLRequest
property NSRunningApplication : a reference to current application’s NSRunningApplication
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding
property WKUserContentController : a reference to current application’s WKUserContentController
property WKWebViewConfiguration : a reference to current application’s WKWebViewConfiguration
property WKUserScriptInjectionTimeAtDocumentEnd : a reference to current application’s WKUserScriptInjectionTimeAtDocumentEnd

property returnCode : 0

–https://www.cresco.co.jp/blog/entry/7427/
— By sgi-chang @ UX Design Center
set myStr to "<!DOCTYPE html>
<html>

<head>
<title>three.js css3d – cresco xmas inspired by periodic table</title>
<meta charset=\"utf-8\">
<meta name=\"viewport\" content=\"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0\">
<link type=\"text/css\" rel=\"stylesheet\" href=\"https://threejs.org/examples/main.css\">
<style>
a {
color: #8ff;
}

#menu {
position: absolute;
bottom: 20px;
width: 100%;
text-align: center;
}

.element {
width: 120px;
height: 160px;
box-shadow: 0px 0px 12px rgba(0, 255, 255, 0.5);
border: 1px solid rgba(127, 255, 255, 0.25);
font-family: Helvetica, sans-serif;
text-align: center;
line-height: normal;
cursor: default;
}

.element:hover {
box-shadow: 0px 0px 12px rgba(0, 255, 255, 0.75);
border: 1px solid rgba(127, 255, 255, 0.75);
}

.element .number {
position: absolute;
top: 20px;
right: 20px;
font-size: 12px;
color: rgba(127, 255, 255, 0.75);
}

.element .symbol {
position: absolute;
top: 40px;
left: 0px;
right: 0px;
font-size: 60px;
font-weight: bold;
color: rgba(255, 255, 255, 0.75);
text-shadow: 0 0 10px rgba(0, 255, 255, 0.95);
}

.element .details {
position: absolute;
bottom: 15px;
left: 0px;
right: 0px;
font-size: 12px;
color: rgba(127, 255, 255, 0.75);
}

button {
color: rgba(127, 255, 255, 0.75);
background: transparent;
outline: 1px solid rgba(127, 255, 255, 0.75);
border: 0px;
padding: 5px 10px;
cursor: pointer;
}

button:hover {
background-color: rgba(0, 255, 255, 0.5);
}

button:active {
color: #000000;
background-color: rgba(0, 255, 255, 0.75);
}
</style>
</head>

<body>
<script src=\"https://threejs.org/examples/jsm/libs/tween.module.min.js\"></script>
<script src=\"https://threejs.org/examples/jsm/controls/TrackballControls.js\"></script>
<script src=\"https://threejs.org/examples/jsm/renderers/CSS3DRenderer.js\"></script>

<div id=\"info\"><a href=\"http://piyocast.com/as\" target=\"_blank\">AppleScript 3D UI Demonstration</a> By Piyomaru Software</div>
<div id=\"container\"></div>
<div id=\"menu\">
<button id=\"table\">TABLE</button>
<button id=\"sphere\">SPHERE</button>
<button id=\"helix\">HELIX</button>
<button id=\"grid\">GRID</button>
</div>

    <!– Import maps polyfill –>
    <!– Remove this when import maps will be widely supported –>
    <script async src=\"https://unpkg.com/es-module-shims@1.5.8/dist/es-module-shims.js\"></script>

    <script type=\"importmap\">
      {
        \"imports\": {
          \"three\": \"https://unpkg.com/three@0.142.0/build/three.module.js\",
          \"OrbitControls\": \"https://unpkg.com/three@0.142.0/examples/jsm/controls/OrbitControls.js\"
        }
      }
    </script>
    
<script type=\"module\">
import * as THREE from ’https://threejs.org/build/three.module.js’;
import { TWEEN } from ’https://threejs.org/examples/jsm/libs/tween.module.min.js’;
import { TrackballControls } from ’https://threejs.org/examples/jsm/controls/TrackballControls.js’;
import { CSS3DRenderer, CSS3DObject } from ’https://threejs.org/examples/jsm/renderers/CSS3DRenderer.js’;
    
var table = [
\"1\", \"Hydrogen\", \"1.00794\", 1, 1,
\"2\", \"Helium\", \"4.002602\", 1, 2,
\"3\", \"Lithium\", \"6.941\", 1, 3,
\"4\", \"Beryllium\", \"9.012182\", 1, 4,
\"5\", \"Boron\", \"10.811\", 1, 5,
\"6\", \"Carbon\", \"12.0107\", 2, 1,
\"7\", \"Nitrogen\", \"14.0067\", 2, 3,
\"8\", \"Oxygen\", \"15.9994\", 3, 1,
\"9\", \"Fluorine\", \"18.9984032\", 3, 3,
\"101\", \"Saturday\", \"July\", 4, 2,
\"I\", \"Moscovium\", \"(290)\", 6, 1,
\"I\", \"Livermorium\", \"(293)\", 6, 2,
\"I\", \"Tennessine\", \"(294)\", 6, 3,
\"I\", \"Titanium\", \"47.867\", 6, 4,
\"I\", \"Vanadium\", \"50.9415\", 6, 5,
\"Y\", \"Chromium\", \"51.9961\", 8, 1,
\"Y\", \"Manganese\", \"54.938045\", 9, 2,
\"Y\", \"Iron\", \"55.845\", 10, 3,
\"Y\", \"Cobalt\", \"58.933195\", 10, 4,
\"Y\", \"Nickel\", \"58.6934\", 10, 5,
\"Y\", \"Copper\", \"63.546\", 11, 2,
\"Y\", \"Zinc\", \"65.38\", 12, 1,
\"O\", \"Gallium\", \"69.723\", 14, 1,
\"O\", \"Copernicium\", \"(285)\", 14, 2,
\"O\", \"Nihonium\", \"(286)\", 14, 3,
\"O\", \"Oganesson\", \"(294)\", 14, 4,
\"O\", \"Neon\", \"20.1797\", 14, 5,
\"O\", \"Sodium\", \"22.98976…\", 15, 1,
\"O\", \"Magnesium\", \"24.305\", 15, 5,
\"O\", \"Aluminium\", \"26.9815386\", 16, 1,
\"O\", \"Silicon\", \"28.0855\", 16, 5,
\"O\", \"Phosphorus\", \"30.973762\", 17, 1,
\"O\", \"Sulfur\", \"32.065\", 17, 2,
\"O\", \"Chlorine\", \"35.453\", 17, 3,
\"O\", \"Argon\", \"39.948\", 17, 4,
\"O\", \"Potassium\", \"39.948\", 17, 5,
\"M\", \"Calcium\", \"40.078\", 1, 7,
\"M\", \"Scandium\", \"44.955912\", 1, 8,
\"M\", \"Roentgenium\", \"(280)\", 1, 9,
\"M\", \"Germanium\", \"72.63\", 1, 10,
\"M\", \"Lead\", \"207.2\", 1, 11,      
\"M\", \"Arsenic\", \"74.9216\", 2, 8,
\"M\", \"Selenium\", \"78.96\", 3, 9,
\"M\", \"Bromine\", \"79.904\", 3, 10,
\"M\", \"Krypton\", \"83.798\", 4, 8,
\"M\", \"Rubidium\", \"85.4678\", 5, 7,
\"M\", \"Strontium\", \"87.62\", 5, 8,
\"M\", \"Yttrium\", \"88.90585\", 5, 9,
\"M\", \"Zirconium\", \"91.224\", 5, 10,
\"M\", \"Niobium\", \"92.90628\", 5, 11,
\"A\", \"Molybdenum\", \"95.96\", 7,8,
\"A\", \"Technetium\", \"(98)\", 7, 9,
\"A\", \"Ruthenium\", \"101.07\", 7, 10,
\"A\", \"Rhodium\", \"102.9055\",7, 11,
\"A\", \"Palladium\", \"106.42\", 8, 7,
\"A\", \"Silver\", \"107.8682\", 8,9,
\"A\", \"Cadmium\", \"112.411\", 9, 7,
\"A\", \"Indium\", \"114.818\", 9, 9,
\"A\", \"Tin\", \"118.71\", 10, 8,
\"A\", \"Antimony\", \"121.76\", 10, 9,
\"A\", \"Gadolinium\", \"157.25\", 10, 10,
\"A\", \"Terbium\", \"158.92535\", 10, 11,
\"R\", \"Dysprosium\", \"162.5\", 12, 7,
\"R\", \"Holmium\", \"164.93032\", 12, 8,
\"R\", \"Erbium\", \"167.259\", 12, 9,
\"R\", \"Thulium\", \"168.93421\", 12, 10,
\"R\", \"Ytterbium\", \"173.054\", 12, 11,
\"R\", \"Lutetium\", \"174.9668\", 13, 7,
\"R\", \"Hafnium\", \"178.49\", 13, 9,
\"R\", \"Samarium\", \"150.36\", 14, 7,
\"R\", \"Europium\", \"151.964\", 14, 9,
\"R\", \"Tantalum\", \"180.94788\", 15, 8,
\"R\", \"Tungsten\", \"183.84\", 15, 10,
\"R\", \"Rhenium\", \"186.207\", 15, 11,
\"U\", \"Osmium\", \"190.23\", 17, 7,
\"U\", \"Iridium\", \"192.217\", 17,8,
\"U\", \"Platinum\", \"195.084\", 17, 9,
\"U\", \"Gold\", \"196.966569\", 17, 10,
\"U\", \"Mercury\", \"200.59\", 18, 11,
\"U\", \"Thallium\", \"204.3833\", 19, 11,
\"U\", \"Bismuth\", \"208.9804\", 20, 7,
\"U\", \"Polonium\", \"(209)\", 20, 8,
\"U\", \"Astatine\", \"(210)\", 20, 9,
\"U\", \"Francium\", \"(223)\", 20, 10,
\"U\", \"Radium\", \"(226)\", 22, 9,
\"U\", \"Actinium\", \"(227)\", 22, 10,
\"U\", \"Thorium\", \"232.03806\", 22, 11,
\"A\", \"Protactinium\", \"231.0588\", 22, 7,
\"A\", \"Uranium\", \"238.02891\", 23, 9,
\"A\", \"Neptunium\", \"(237)\", 23, 8,
\"A\", \"Plutonium\", \"(244)\", 23, 9,
\"A\", \"Americium\", \"(243)\", 23, 10,
\"A\", \"Curium\", \"(247)\", 23, 11,
\"S\", \"Berkelium\", \"(247)\", 24, 7,
\"S\", \"Californium\", \"(251)\", 24, 8,
\"S\", \"Einstenium\", \"(252)\", 24, 9,
\"S\", \"Fermium\", \"(257)\", 24, 11,
\"S\", \"Mendelevium\", \"(258)\", 25, 7,
\"S\", \"Nobelium\", \"(259)\", 25, 9,
\"S\", \"Lawrencium\", \"(262)\", 25, 11,
\"S\", \"Rutherfordium\", \"(267)\", 26, 7,
\"S\", \"Dubnium\", \"(268)\", 26, 9,
\"S\", \"Seaborgium\", \"(271)\", 26, 10,
\"S\", \"Bohrium\", \"(272)\", 26, 11,
\"A\", \"Hassium\", \"(270)\", 27, 8,
\"B\", \"Meitnerium\", \"(276)\", 27, 9,
\"C\", \"Darmstadium\", \"(281)\", 27, 8,
\"D\", \"Tellurium\", \"127.6\", 27, 9,
\"E\", \"Iodine\", \"126.90447\", 27, 10,
\"F\", \"Xenon\", \"131.293\", 28, 9,
\"G\", \"Caesium\", \"132.9054\", 28, 10,
\"H\", \"Barium\", \"132.9054\", 28, 11,
\"I\", \"Lanthanum\", \"138.90547\", 29, 8,
\"J\", \"Cerium\", \"140.116\", 29, 9,
\"K\", \"Praseodymium\", \"140.90765\", 29, 10,
\"L\", \"Neodymium\", \"144.242\", 29, 8,
\"M\", \"Promethium\", \"(145)\", 29, 9,
  \"PS\", \"Piyomaru Software\", \"(PiyoPiyo)\", 29, 10,  
  \"AS\", \"AppleScript\", \"(osalang)\", 29, 11,  
];

var camera, scene, renderer;
var controls;
var objects = [];
var targets = { table: [], sphere: [], helix: [], grid: [] };
init();
animate();
    
function init() {
camera = new THREE.PerspectiveCamera(40, window.innerWidth / window.innerHeight, 1, 10000);
camera.position.z = 3000;
scene = new THREE.Scene();
      
// table
for (var i = 0; i < table.length; i += 5) {
      
var element = document.createElement(’div’);
element.className = ’element’;

     //element.style.backgroundColor = ’rgba(128,0,64,’ + ( Math.random() * 0.5 + 0.25 ) + ’)’;
    //element.style.backgroundColor = ’rgba(64,0,128,’ + ( Math.random() * 0.5 + 0.25 ) + ’)’;
//element.style.backgroundColor = ’rgba(0,0,0,’ + ( Math.random() * 0.5 + 0.25 ) + ’)’;
element.style.backgroundColor = ’rgba(0,127,127,’ + ( Math.random() * 0.5 + 0.25 ) + ’)’;
//element.style.backgroundColor = ’rgba(18,77,174,’ + (Math.random() * 0.5 + 0.25) + ’)’;

var number = document.createElement(’div’);
number.className = ’number’;
number.textContent = (i / 5) + 1;
element.appendChild(number);
var symbol = document.createElement(’div’);
symbol.className = ’symbol’;
symbol.textContent = table[i];
element.appendChild(symbol);
var details = document.createElement(’div’);
details.className = ’details’;
details.innerHTML = table[i + 1] + ’<br>’ + table[i + 2];
element.appendChild(details);
var object = new CSS3DObject(element);
object.position.x = Math.random() * 4000 – 2000;
object.position.y = Math.random() * 4000 – 2000;
object.position.z = Math.random() * 4000 – 2000;
scene.add(object);
objects.push(object);
//
var object = new THREE.Object3D();
object.position.x = (table[i + 3] * 140) – 1330;
object.position.y = – (table[i + 4] * 180) + 990;
targets.table.push(object);
}
      
// sphere
var vector = new THREE.Vector3();
for (var i = 0, l = objects.length; i < l; i++) {
var phi = Math.acos(- 1 + (2 * i) / l);
var theta = Math.sqrt(l * Math.PI) * phi;
var object = new THREE.Object3D();
object.position.setFromSphericalCoords(800, phi, theta);
vector.copy(object.position).multiplyScalar(2);
object.lookAt(vector);
targets.sphere.push(object);
}
      
// helix
var vector = new THREE.Vector3();
for (var i = 0, l = objects.length; i < l; i++) {
var theta = i * 0.175 + Math.PI;
var y = – (i * 8) + 450;
var object = new THREE.Object3D();
object.position.setFromCylindricalCoords(900, theta, y);
vector.x = object.position.x * 2;
vector.y = object.position.y;
vector.z = object.position.z * 2;
object.lookAt(vector);
targets.helix.push(object);
}
      
// grid
for (var i = 0; i < objects.length; i++) {
var object = new THREE.Object3D();
object.position.x = ((i % 5) * 400) – 800;
object.position.y = (- (Math.floor(i / 5) % 5) * 400) + 800;
object.position.z = (Math.floor(i / 25)) * 1000 – 2000;
targets.grid.push(object);
}
      
//
renderer = new CSS3DRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById(’container’).appendChild(renderer.domElement);
      
//
controls = new TrackballControls(camera, renderer.domElement);
controls.minDistance = 500;
controls.maxDistance = 6000;
controls.addEventListener(’change’, render);
      
var button = document.getElementById(’table’);
button.addEventListener(’click’, function () {
transform(targets.table, 2000);
}, false);
      
var button = document.getElementById(’sphere’);
button.addEventListener(’click’, function () {
transform(targets.sphere, 2000);
}, false);
      
var button = document.getElementById(’helix’);
button.addEventListener(’click’, function () {
transform(targets.helix, 2000);
}, false);
      
var button = document.getElementById(’grid’);
button.addEventListener(’click’, function () {
transform(targets.grid, 2000);
}, false);
      
transform(targets.table, 2000);
//
window.addEventListener(’resize’, onWindowResize, false);
}
    
function transform(targets, duration) {
TWEEN.removeAll();
for (var i = 0; i < objects.length; i++) {
var object = objects[i];
var target = targets[i];
new TWEEN.Tween(object.position)
.to({ x: target.position.x, y: target.position.y, z: target.position.z }, Math.random() * duration + duration)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
new TWEEN.Tween(object.rotation)
.to({ x: target.rotation.x, y: target.rotation.y, z: target.rotation.z }, Math.random() * duration + duration)
.easing(TWEEN.Easing.Exponential.InOut)
.start();
}
new TWEEN.Tween(this)
.to({}, duration * 2)
.onUpdate(render)
.start();
}
    
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
render();
}
    
function animate() {
requestAnimationFrame(animate);
TWEEN.update();
controls.update();
}
    
function render() {
renderer.render(scene, camera);
}
</script>
</body>

</html>"

set paramObj to {myMessage:"WebGL & three.js Test", mySubMessage:"This is a WebGL UI using three.js", htmlStr:myStr}
–my browseStrWebContents:paramObj–for debug
my performSelectorOnMainThread:"browseStrWebContents:" withObject:(paramObj) waitUntilDone:true

on browseStrWebContents:paramObj
  set aMainMes to myMessage of paramObj
  
set aSubMes to mySubMessage of paramObj
  
set htmlString to (htmlStr of paramObj)
  
  
set aWidth to 1600
  
set aHeight to 900
  
  
–WebViewをつくる
  
set aConf to WKWebViewConfiguration’s alloc()’s init()
  
  
–指定HTML内のJavaScriptをFetch
  
set jsSource to pickUpFromToStr(htmlString, "<script src", "</script>") of me
  
  
set userScript to WKUserScript’s alloc()’s initWithSource:jsSource injectionTime:(WKUserScriptInjectionTimeAtDocumentEnd) forMainFrameOnly:true
  
set userContentController to WKUserContentController’s alloc()’s init()
  
userContentController’s addUserScript:(userScript)
  
aConf’s setUserContentController:userContentController
  
  
set aWebView to WKWebView’s alloc()’s initWithFrame:(current application’s NSMakeRect(0, 0, aWidth, aHeight)) configuration:aConf
  
aWebView’s setNavigationDelegate:me
  
aWebView’s setUIDelegate:me
  
aWebView’s setTranslatesAutoresizingMaskIntoConstraints:true
  
using terms from scripting additions
    set bURL to |NSURL|’s fileURLWithPath:(POSIX path of (path to me))
  end using terms from
  
aWebView’s loadHTMLString:htmlString baseURL:(bURL)
  
  
— set up alert  
  
set theAlert to NSAlert’s alloc()’s init()
  
tell theAlert
    its setMessageText:aMainMes
    
its setInformativeText:aSubMes
    
its addButtonWithTitle:"OK"
    
–its addButtonWithTitle:"Cancel"
    
its setAccessoryView:aWebView
    
    
set myWindow to its |window|
  end tell
  
  
— show alert in modal loop
  
NSRunningApplication’s currentApplication()’s activateWithOptions:0
  
my performSelectorOnMainThread:"doModal:" withObject:(theAlert) waitUntilDone:true
  
  
–Stop Web View Action
  
set bURL to |NSURL|’s URLWithString:"about:blank"
  
set bReq to NSURLRequest’s requestWithURL:bURL
  
aWebView’s loadRequest:bReq
  
  
if (my returnCode as number) = 1001 then error number -128
end browseStrWebContents:

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

on viewDidLoad:aNotification
  return true
end viewDidLoad:

on fetchJSSourceString(aURL)
  set jsURL to |NSURL|’s URLWithString:aURL
  
set jsSourceString to NSString’s stringWithContentsOfURL:jsURL encoding:(NSUTF8StringEncoding) |error|:(missing value)
  
return jsSourceString
end fetchJSSourceString

on pickUpFromToStr(aStr as string, s1Str as string, s2Str as string)
  set a1Offset to offset of s1Str in aStr
  
if a1Offset = 0 then return false
  
set bStr to text (a1Offset + (length of s1Str)) thru -1 of aStr
  
set a2Offset to offset of s2Str in bStr
  
if a2Offset = 0 then return false
  
set cStr to text 1 thru (a2Offset – (length of s2Str)) of bStr
  
return cStr as string
end pickUpFromToStr

–リストを任意のデリミタ付きでテキストに
on retArrowText(aList, aDelim)
  set aText to ""
  
set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to aDelim
  
set aText to aList as text
  
set AppleScript’s text item delimiters to curDelim
  
return aText
end retArrowText

on array2DToJSONArray(aList)
  set anArray to current application’s NSMutableArray’s arrayWithArray:aList
  
set jsonData to current application’s NSJSONSerialization’s dataWithJSONObject:anArray options:(0 as integer) |error|:(missing value) –0 is
  
set resString to current application’s NSString’s alloc()’s initWithData:jsonData encoding:(current application’s NSUTF8StringEncoding)
  
return resString
end array2DToJSONArray

on parseByDelim(aData, aDelim)
  set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to aDelim
  
set dList to text items of aData
  
set AppleScript’s text item delimiters to curDelim
  
return dList
end parseByDelim

★Click Here to Open This Script 

(Visited 138 times, 4 visits today)
Posted in 3D dialog JavaScript | Tagged 12.0savvy 13.0savvy WKWebView | 1 Comment

OpenAIでchatに対する応答文を取得

Posted on 3月 6 by Takaaki Naganoya

OpenAIが提供しているREST APIを呼び出して、チャットに対する応答を生成するAppleScriptです。実行のためにはOpenAIのWebサイトにサインアップして、実行のためのAPI Keyを取得してください。

ChatGPTなどのサービスを提供しているOpenAIにサインアップして、各種サービスをAppleScriptから利用できます。Freeアカウントでは1分あたりに発行できるクエリー数の上限が低めに設定されていますが、実験を行う程度であれば十分なレベルでしょう。

https://platform.openai.com/docs/introduction

「chat」は、いわゆるChatGPTでよく知られている処理で、チャットに応答するものです。この呼び出し方に対して、さらにroleとして「system」「user」「assistant」などの役割を指定することで、チャットらしいやりとりを生成するようです(Chat completion)。

AppleScript名:Chat.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/03/05
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

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

property NSString : a reference to current application’s NSString
property NSCountedSet : a reference to current application’s NSCountedSet
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set myText to "こんにちは"

set barerKey to "xx-XXXXXXXxXxxxxXxxXXxXXXXxxxXXxxxxXXxxxXXxXXxxXXxx"

set aText to "curl https://api.openai.com/v1/chat/completions -H ’Content-Type: application/json’ -H ’Authorization: Bearer " & barerKey & "’ -d ’{\"model\": \"gpt-3.5-turbo\",\"messages\": [{\"role\": \"user\", \"content\": \"" & myText & "\"}]}’"
set sRes to do shell script aText

set jsonString to NSString’s stringWithString:sRes
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
set aRes to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
set chatRes to (aRes’s valueForKeyPath:"choices.message.content") as list
–>{"こんにちは!こんにちはと言うと、こんにちはと返してくださる方が多いですね。私はAIアシスタントなので、いつでもお話し相手になれます。何かお話を聞かせてください。"}
–> {"、こんにちは! 私はAIアシスタントです。何かお手伝いできることはありますか?"}
–> {"こんにちは!私はAIアシスタントです。何かお手伝いできますか?"}
–> {"、私はAIアシスタントです。何かお手伝いできることはありますか?"}
–> {"こんにちは!こんにちはは、日本語で「こんにちは」と書き、挨拶の一つです。相手と会話をする際に使われる一般的な挨拶の言葉で、おはようございます、こんにちは、こんばんはなどがあります。どうぞよろしくお願いします!"}

★Click Here to Open This Script 

(Visited 39 times, 2 visits today)
Posted in JSON Natural Language Processing Network REST API | Tagged 12.0savvy 13.0savvy ChatGPT | Leave a comment

OpenAIで質問に対する回答を生成(Compilations)

Posted on 2月 26 by Takaaki Naganoya

OpenAIが提供しているREST APIを呼び出して、質問に対する回答を生成するAppleScriptです。実行のためにはOpenAIのWebサイトにサインアップして、実行のためのAPI Keyを取得してください。

ChatGPTなどのサービスを提供しているOpenAIにサインアップして、各種サービスをAppleScriptから利用できます。Freeアカウントでは1分あたりに発行できるクエリー数の上限が低めに設定されていますが、実験を行う程度であれば十分なレベルでしょう。

https://platform.openai.com/docs/introduction

「質問に対する回答を生成」は、いわゆるChatGPTでよく知られている処理で、対話的に質問文に回答するものです。回答内容が正しいかどうかはちょっとアレですが、自然言語処理もこのレベルまで来たのかと感心させられます。

対話っぽい動作(前回の問い合わせを踏まえた上で回答する)を考えて「user」パラメータを付けて呼び出していますが(ここも自分のユーザーアカウントに書き換えてください)、いまひとつWebブラウザ上で問い合わせを行ったときのような「つながり」を感じられないので、何かまだ指定する必要があるのかもしれません。

AppleScript名:Compilations(質問に対する回答を生成).scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/02/24
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

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

property NSString : a reference to current application’s NSString
property NSCountedSet : a reference to current application’s NSCountedSet
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set myText to "バンダイナムコのアーケードゲーム「戦場の絆1」の初代プロデューサーの名前は、小山順一朗さんです。"

set barerKey to "xx-XXXXXXXxXxxxxXxxXXxXXXXxxxXXxxxxXXxxxXXxXXxxXXxx"

set sRes to (do shell script "curl https://api.openai.com/v1/completions -H ’Content-Type: application/json’ -H ’Authorization: Bearer " & barerKey & "’ -d ’{\"model\": \"text-davinci-003\", \"prompt\": \"" & myText & "\", \"max_tokens\": 200, \"temperature\": 0, \"user\": \"maro_ml@piyocast.com\"}’")

set jsonString to NSString’s stringWithString:sRes
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
set aRes to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
set modelRes to aRes as {anything, record}

–>{|id|:"cmpl-6nMNGJzTFei6eMbn1rnMgMN9ML4qi", object:"text_completion", created:1.677222098E+9, model:"text-davinci-003", choices:{{|index|:0, finish_reason:"stop", logprobs:missing value, |text|:"小山順一朗さんは、バンダイナムコのゲームプロデューサーとして、「戦場の絆1」をはじめとした数々のアーケードゲームをプロデュースしてきました。また、「戦場の絆1」のプロデューサーとして、「戦場の絆2」「戦場の絆3」「戦場の絆4」などのシリーズをプロデュースしています。"}}, usage:{total_tokens:224, completion_tokens:163, prompt_tokens:61}}

★Click Here to Open This Script 

(Visited 26 times, 1 visits today)
Posted in Natural Language Processing REST API Text | Tagged 12.0savvy 13.0savvy ChatGPT | Leave a comment

OpenAIで文章の感情検出(Moderations)

Posted on 2月 26 by Takaaki Naganoya

OpenAIが提供しているREST APIを呼び出して、指定文章の感情検出を行うAppleScriptです。実行のためにはOpenAIのWebサイトにサインアップして、実行のためのAPI Keyを取得してください。

ChatGPTなどのサービスを提供しているOpenAIにサインアップして、各種サービスをAppleScriptから利用できます。Freeアカウントでは1分あたりに発行できるクエリー数の上限が低めに設定されていますが、実験を行う程度であれば十分なレベルでしょう。

https://platform.openai.com/docs/introduction

「文章の感情検出」は、ユーザーサポートなどの現場においてユーザーからの投稿が質問などのものなのか、あるいは感情的な文章なのかといった「当たり」をつけるために用いられているといった印象があります。

ただ、「I want to kill him.」という例文に対して「hate」が検出されないなど、ややその評価内容には疑問の余地が残されているようです。

AppleScript名:Moderations(感情検出).scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/02/24
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

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

property NSString : a reference to current application’s NSString
property NSCountedSet : a reference to current application’s NSCountedSet
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set aSentence to "I want to kill him."

set barerKey to "xx-XXXXXXXxXxxxxXxxXXxXXXXxxxXXxxxxXXxxxXXxXXxxXXxx"
set sRes to (do shell script "curl https://api.openai.com/v1/moderations -H ’Content-Type: application/json’ -H ’Authorization: Bearer " & barerKey & "’ -d ’{\"input\": \"" & aSentence & "\" }’")

set jsonString to NSString’s stringWithString:sRes
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
set aRes to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)

set mRes to aRes as {anything, record}
–> {|id|:"modr-6o8PPeHjWYIH5z5Qi79etbe8JaWY8", model:"text-moderation-004", results:{{flagged:true, category_scores:{sexual:3.26660915561661E-6, |sexual/minors|:2.58405265185502E-7, |hate/threatening|:2.28086973947939E-5, hate:0.007466733921, |self-harm|:1.23088886994083E-6, violence:0.794520378113, |violence/graphic|:4.90069034242424E-8}, categories:{sexual:false, |sexual/minors|:false, |hate/threatening|:false, hate:false, |self-harm|:false, violence:true, |violence/graphic|:false}}}}

★Click Here to Open This Script 

(Visited 24 times, 1 visits today)
Posted in Natural Language Processing REST API Text | Tagged 12.0savvy 13.0savvy ChatGPT | Leave a comment

OpenAIで文章のベクトル化(Embedding)

Posted on 2月 26 by Takaaki Naganoya

OpenAIが提供しているREST APIを呼び出して、指定文章のベクトル化を行うAppleScriptです。実行のためにはOpenAIのWebサイトにサインアップして、実行のためのAPI Keyを取得してください。

ChatGPTなどのサービスを提供しているOpenAIにサインアップして、各種サービスをAppleScriptから利用できます。Freeアカウントでは1分あたりに発行できるクエリー数の上限が低めに設定されていますが、実験を行う程度であれば十分なレベルでしょう。

https://platform.openai.com/docs/introduction

「文章のベクトル化」は、大量の候補文を用意しておいてベクトル化し、新たにユーザーが与えた文章との「類似度」を計算するためのものです。

AppleScript名:Embedding(文章のベクトル化).scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/02/24
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

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

property NSString : a reference to current application’s NSString
property NSCountedSet : a reference to current application’s NSCountedSet
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set myText to "今日はいい天気です。"

set barerKey to "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
set sRes to (do shell script "curl https://api.openai.com/v1/embeddings -H ’Content-Type: application/json’ -H ’Authorization: Bearer " & barerKey & "’ -d ’{\"input\": \"" & myText & "\", \"model\":\"text-embedding-ada-002\"}’")

set jsonString to NSString’s stringWithString:sRes
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
set aRes to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
set modelRes to aRes as {anything, record}
–> {object:"list", |data|:{{|index|:0, object:"embedding", embedding:{0.0024673557, 0.0037366515, -0.005702117, -0.025023261, 0.010659494, -0.0024349757, 0.0038791234, -0.031266123, 0.005248797, -0.023909388, -0.0052941293, 0.008710219, -0.0028316306, -0.019039437, -0.013780926, -0.009519719, 0.01660446, -0.020762052, 0.019881317, -0.025748573, 0.037897546, 0.025981707, -0.006569901, -0.01387159, -0.023209982, 0.0051743235, 0.014182438, -0.018974677, 0.031032987, -0.026655212, 0.029919116, -0.00975933, -0.007019983, 0.022381052, 0.010186747, -0.032120954, -0.023054557, 0.01536107, -0.0049476633, 0.005919063, 0.01542583, -0.019363238, 0.015335166, -0.0029741025, -0.02567086, 0.008626031, -0.008295755, 0.0018116607, -0.004814905, 0.028546205, 0.011533754, -0.006395049, -0.040876508, -0.038855996, -5.7595916E-4, 0.006106867, -0.014078822, -1.681736E-4, -0.005365365, -0.01260877, -0.0025499247, -0.013949302, -0.009280107, 0.01925962, 0.007266071, -0.01451919, -0.020917477, -0.0051937513, -0.018197557, 0.009701047, 0.008813835, -0.0028105837, -4.6546242E-4, -0.035669804, 0.008813835, 0.0023507876, -0.013003807, -0.010562355, -0.0016028098, 0.008904499, 0.015995719, -0.03269084, -0.0109638665, -0.006909891, 0.0061554373, 0.0031861917, -0.014117678, 0.019440949, -1.770781E-4, -0.017057782, 0.011592038, 0.0014376718, 0.023171125, -0.0041090213, -0.006637899, 0.0035877035, 0.01633247, 0.031136604, 0.011158146, -0.026784733, -0.0041122595, -0.0016950928, 2.7664658E-4, 0.0033416154, -0.051367626, -0.0082892785, 0.027173292, -0.008082047, 0.02120242, -0.038234297, -0.015179742, -0.006909891, 4.5251043E-4, -0.039918058, -0.024518132, 0.008962783, 0.004562341, 0.0014311958, -0.012168402, -3.0922896E-4, 0.018624973, 0.010070179, -0.0012701054, -0.004737193, 0.006450095, 0.01150785, -0.02890886, -0.016228853, -0.011650322, 8.2771364E-4, 0.01426015, 0.005112801, 0.0041187354, 0.007466827, 0.0037139854, 0.012984378, -0.025632005, 0.0197777, -0.010756634, 0.018093942, 0.006236387, 0.035177626, -0.019699989, -0.018236414, -0.013107422, 0.012401538, 0.008600127, -0.019415045, 0.01354779, -0.017562909, 0.020787956, -0.012511631, 0.029349228, 0.017472245, 0.023313597, 0.026784733, 9.843518E-4, 0.017239109, -0.0036265594, -0.013573694, 0.028934764, -0.0132045625, 0.03590294, 0.007725867, 8.362134E-4, 0.02644798, 0.009739903, 0.0050577554, 0.007000555, -2.8352733E-4, -0.0048537613, 0.023184076, -0.030307677, 0.0038305535, -0.010251506, 0.034115564, 0.016280662, 0.005864017, -0.0049185213, -0.017485198, -0.038985513, -8.707183E-5, 0.014558046, -0.005430125, 0.0011486803, -0.011630895, 0.024453372, 0.0055110753, -0.009849994, -0.026422076, 0.0330535, 0.038027067, 0.013405318, -0.013884542, -0.6204525, -0.027976315, -0.0013024854, -0.0033578055, 0.03079985, 0.0029174376, 0.014506238, 0.018132798, -0.01905239, 0.016643317, -0.01290019, 0.009973039, -0.015827341, -0.0017614717, 0.0027199197, -0.016461989, -0.009824091, -0.0061845793, -0.025852188, 0.01796442, -0.016410181, 0.01562011, -0.022186773, -0.018236414, 0.014337862, -0.016215902, -0.009571526, -0.027276909, -0.019997885, 0.041705433, -0.036576442, 0.03901142, 0.014998414, -0.014117678, 0.048181433, -0.0039438833, -0.029789595, 0.050564602, 0.019415045, 0.026046468, -0.024220238, -0.017148446, 0.015827341, -0.0099082785, 0.011112815, -0.006961699, 0.024025956, -0.015153838, 0.01801623, 0.0025628766, -0.0042353035, -0.0033707574, 0.0029384845, -0.0015914767, -0.012731814, 0.016695125, 0.039063226, -0.030748043, -0.01163737, 0.0014692423, -0.006589329, 0.009383723, -0.013949302, -0.010950915, -0.016449038, 0.01562011, -0.007492731, 0.005987061, 0.020723198, 0.0031068607, -0.0051095635, 0.0049347114, 0.014609854, 0.018093942, 0.011125767, 0.013729118, 0.037742123, -0.0028915335, -0.020956334, 0.014311958, 0.011695654, -0.019712942, -0.018948773, 0.0023313598, 0.006877511, -0.012569915, -0.038674667, -0.01822346, 0.021435557, -0.0042968253, 0.010769586, 0.02028283, 0.024090717, 0.0019444188, 0.008263375, 0.018327078, -0.008470607, -0.024803076, 0.0041640676, 0.014570998, -0.0054625054, 0.011061006, 0.016669221, 0.008412323, 0.007201311, 0.009552099, -0.026681116, -0.006521331, -0.0035650374, -0.01840479, 0.018003277, -0.01510203, -0.01796442, 0.0025207826, 0.024272045, -0.032898076, 0.016837597, 0.012550486, 0.00843175, 0.008412323, 0.0090987785, 0.0060971533, 0.019712942, -0.008502987, -0.021590982, 0.029375132, -0.007486255, -0.012971426, -0.0032282856, 0.007421495, -0.010633591, 0.0019897507, 0.016034573, -0.019894268, 0.03033358, -0.031551067, 0.008308707, -0.0126411505, 0.04802601, -0.011876983, -0.027017869, -0.014221294, -0.010491119, 0.017718334, -0.0026762066, -0.016449038, -0.01490775, -0.005760401, -0.026914252, 0.013340558, 0.007123599, 0.004520247, -0.007745295, 0.022925036, -0.018871062, -0.0026389696, 0.007777675, -0.008898023, -0.008308707, 3.936193E-5, 0.009072875, 0.0013850543, -0.01464871, 0.006006489, -0.005925539, -0.01866383, -0.033727, 0.016733982, -0.006246101, -0.023054557, -0.016695125, -0.0042061615, -0.009610383, 0.011203478, 0.0089109745, -0.016759885, 0.0016837597, -0.005423649, 0.0045688176, -0.016539702, -0.009985991, -0.027147388, -0.015335166, 0.0021548886, -0.0032590465, -0.007058839, 0.029711884, 0.04025481, -0.006621709, 0.021629836, -0.008295755, 0.025165733, -0.008107951, 0.008127379, 0.036343306, -0.025204588, 0.0011932028, 0.02735462, 0.015982766, 0.017537005, 0.012323827, 0.009215347, 0.014104726, -0.0120777385, -4.7841444E-4, -0.021318989, 0.007240167, -0.01231735, 0.0020010837, 0.01098977, 0.0010321124, -0.022044301, -0.019427998, 0.0024592606, -0.01315923, 0.019130101, 0.0025304966, -6.358622E-4, 0.008107951, -0.018521357, 0.007272547, 0.016733982, -0.0016934738, -0.04686033, -0.029064285, -0.014493286, 0.012272018, 0.03131793, 0.0130167585, -0.007687011, -0.024712412, -0.014855942, -0.02249762, 0.025632005, 0.004209399, -0.060459927, 0.0032234285, -0.018599069, 0.054553818, 0.03800116, 0.007557491, -0.0014789563, 0.006760943, -0.030773947, 2.950627E-4, 0.016837597, 0.04349281, 0.008703743, 0.0018148988, 0.0038273155, -0.015995719, -0.036187883, -0.013275798, -0.00911173, 0.007207787, -0.058491223, 0.0019071817, -0.014039966, 0.01516679, 0.044891626, 0.012680006, 0.04551332, -0.0021111758, -0.0027927747, 0.020256925, 0.0024997357, 0.016513798, -0.03279446, -0.007706439, 0.0010264459, -0.0021678407, 0.005261749, 0.0023783108, -0.009170014, 0.007168931, -0.02054187, -0.008211567, -0.0029433416, 0.0051516574, 0.015089078, 6.973841E-4, -0.037534893, -0.010037798, 0.01222021, -0.0021937448, -0.013832734, -0.012945523, -0.034452315, -0.022653045, 0.018003277, 0.015581254, 0.028028125, -0.012809526, 8.872119E-4, 0.012123071, -0.009681619, 0.038855996, -0.0032655227, -0.059475575, -0.027898604, 0.029064285, -0.014078822, 0.022665996, -0.035643898, 0.005067469, 4.998662E-4, -0.008230994, -0.0024284997, 2.5215923E-4, 0.011779842, -0.0052747014, -0.016941214, -0.019635228, -0.017226158, -0.0037431275, 0.0037269376, -0.0046627196, -0.013923398, 0.029375132, -0.013534838, -0.019272573, -0.0034355174, -0.0044490113, 0.012725338, 0.035151724, 0.0014061013, 0.018132798, 0.029867308, 0.019971982, 6.2210066E-4, -0.016358374, -0.02008855, 3.7161106E-5, -0.014596902, 0.014208342, 0.0022034587, 0.009571526, -0.011222906, 0.007188359, -0.009927707, -0.016112287, -0.0036168455, -0.0020367017, -0.013379415, -0.013923398, 0.01445443, -5.3872215E-4, 0.015309262, 0.009519719, 0.0013340558, -0.006100391, 0.031991437, 0.020153308, -0.007589871, -0.007065315, 0.01464871, -0.010374551, -0.008373467, -0.010562355, 0.01951866, -0.0097204745, 0.025450677, -0.013379415, -0.013431222, -0.0042871116, 0.032716747, 0.014804134, 0.013314654, -0.009694571, 0.0020707007, -0.01471347, 0.014959558, -0.010303315, -0.007797103, 0.019946078, 0.016487895, -0.0285203, -0.03105889, -0.008923926, 0.040954217, -0.0272251, -0.009843519, -0.009144111, 0.013340558, -0.011462518, -0.021603933, -0.007725867, 8.535165E-5, -0.0140140625, -0.03144745, -0.008075571, -0.01691531, -0.0063497173, -0.020153308, -0.0015145743, -0.005925539, -0.033675194, 9.414484E-4, 0.025049165, 0.02994502, 0.007622251, -0.017018925, -0.009273631, 0.024712412, -0.008800883, -0.005248797, 0.020438254, -0.020256925, -0.014182438, 0.0013648168, 0.006832179, -2.2463621E-4, 0.006683231, 0.01257639, 0.018832205, 0.020658437, 0.01458395, 0.018573165, -0.011630895, -0.0097204745, 0.008820311, 0.0119611705, -0.026046468, -0.0018278507, 0.027769083, -0.01626771, -0.016461989, -5.9133966E-4, -7.4878737E-4, 0.03136974, 0.016461989, -8.305469E-4, 0.007732343, 0.0041414015, 0.029271515, -0.010011895, 0.037612602, -2.3637396E-4, -0.0039762636, 0.02327474, 0.006550473, 0.007823007, 0.0058963974, -0.035825226, 0.010510546, -0.01730387, 0.038286105, -0.009053446, 0.025761524, -0.008690791, -0.01821051, -0.028235355, -0.01406587, 0.0115855625, -0.010089607, 0.027769083, -0.0050868974, -0.027717276, -0.013910446, -0.023404261, -0.0039730254, 0.036783677, -0.01613819, -0.030229963, -0.030022731, -0.010018371, 0.01413063, -0.015840294, 0.006871035, -0.02534706, -0.012744767, -8.1455924E-5, 0.016423134, 0.022860277, -0.009001639, -0.005990299, -0.02994502, -5.6786416E-4, 0.013431222, -0.0291679, -0.0035035156, -0.014570998, -0.0010402073, 0.0029190567, 0.021940686, 0.017316822, 0.0049476633, -0.011443091, -0.009539147, -0.0034419936, 0.0045526274, -6.1521993E-4, -0.025852188, 0.0053394614, 0.009118207, -0.0016384277, -0.008936878, -0.015697822, -0.012492202, 0.0027361095, -7.131694E-4, -0.007039411, -0.007654631, -0.033856522, 0.0022892656, -0.014480334, -0.019065341, 0.005048041, 0.043363288, 0.007356735, 0.008082047, -1.9427997E-4, 0.026214844, -0.010478167, 0.02146146, -0.009701047, -0.0010499214, -0.017057782, -0.01069835, -0.0030793375, 0.022640092, -0.0076934868, 0.008891547, 0.010290363, 0.02243286, 0.020140357, -0.01150785, 0.0053977454, -0.01137833, 0.015982766, -0.013884542, 0.0036362736, 0.010575307, -0.018391838, -0.0045105335, -0.0032979026, -0.020917477, -0.026603404, 0.022601238, -2.0983754E-5, -0.0041932096, 0.006087439, -0.026072372, -0.019156005, -0.016721029, -0.008321659, 0.0050156615, -0.02547658, 0.04447716, 0.057714105, 0.0050286134, -0.024712412, -0.05911292, -0.020503012, -0.0016181903, -0.0036589394, 0.010750159, 0.013534838, -0.014480334, -0.007874815, 0.03800116, -0.0048408094, -5.1241345E-4, 0.027017869, 0.023481973, -0.01659151, 0.0027749657, 0.01769243, -0.019207813, 0.018689733, 0.010303315, -0.015646014, -0.0343487, -0.013858638, -0.006242863, 0.021616885, -0.025813332, 0.022769613, 0.023987101, 0.0034743736, 0.015866198, -0.021629836, -0.015089078, -0.0020723196, -0.0026082087, 0.02573562, -0.018508404, 0.017316822, -0.008237471, 0.030022731, 0.0050771832, 0.0011041579, -0.018430693, 0.0427934, 2.0824384E-4, -0.020386444, -0.009066399, 0.014881846, 0.014221294, -0.006252577, 0.00962981, 0.014350814, -0.025916949, -0.013703214, 0.013431222, 0.0037139854, -7.7023916E-4, -0.012304398, -0.015050222, -0.02513983, -0.0014125773, -0.026603404, -0.008425275, -0.0049994714, -0.015542398, 0.016798742, -0.028779339, 0.028882956, 0.028727531, -0.0031748586, -0.012563438, 0.03131793, -0.04064337, 0.013975206, -0.01898763, 0.0022083158, 0.008444703, -0.012654102, 5.2779395E-4, -0.0037334135, 0.0054042214, 0.020490061, -8.2690414E-4, -0.0226919, 0.010096082, 0.011501375, -0.0043518716, -0.006488951, 0.022147916, 0.014959558, 0.0033189496, -0.012647626, -0.04569465, 0.020373493, -0.0010296839, 0.011164622, 0.007531587, -0.0262537, 0.009247727, 0.0013874829, 0.007674059, -0.017679477, -0.021772308, -0.015063174, -0.0028818196, 0.009947134, -0.012783622, -0.0051354673, 0.007097695, -0.012686483, -2.7361096E-4, 0.0048051914, -0.007596347, 0.014402622, 0.028623916, 0.03864876, -0.0051710852, 0.0021613648, -0.01231735, -0.025204588, 0.0033319015, -0.02191478, -0.032509517, -0.021694597, 4.6141492E-4, 0.025230492, 4.658672E-4, -0.014350814, -0.03592884, -0.0022552668, -0.043026537, -0.0013559123, -0.016954165, 0.024790125, 0.0056049773, -0.0040442613, -0.0028283927, 0.04038433, 0.0022504097, -0.0052293693, -0.022458766, -0.007615775, -0.028675724, -0.0035779895, 0.0038791234, -0.004491105, -0.021422604, -0.03320892, 0.0055564074, -0.005734497, 0.009655715, 0.035695706, 0.0041381633, 0.0023847867, -0.011048054, -0.0265775, -0.005371841, 0.009118207, -0.009221823, -0.020231022, -0.014739374, 0.0027522997, 0.008677838, 0.004801953, 0.01581439, 0.005579073, 0.0051160394, 0.01082787, -0.029530555, -0.016565606, -0.020723198, -0.043984987, -0.009616858, -0.011261762, 0.0052455594, 0.02067139, 0.010944438, -0.025049165, -0.01536107, 0.01626771, -0.009882375, -0.010866727, 0.0033642815, -0.007376163, 5.3710316E-4, 0.0027474426, 0.01299733, -0.011229383, -0.020399397, 0.025541341, -0.021772308, -0.039503593, 0.0015623348, 0.010005418, -0.03390833, -0.009934182, 0.011533754, -0.030877564, 0.0027296336, -0.027043773, 0.03364929, -0.03351977, 0.018301174, -8.001906E-4, -0.01822346, -0.0013599598, 0.013599598, 0.009927707, -0.017925566, 0.019453902, 0.2832861, -0.01374207, -0.009221823, 0.038027067, 0.0122072585, 0.019130101, 0.011941742, -0.0066314233, 0.010368074, 0.014545094, -0.019389141, -0.010232079, -0.0017987087, 0.008651935, 0.018547261, -0.016902357, -0.020010836, -0.012246114, -0.03105889, -0.013178658, 0.011935267, 0.0020399396, 0.008684315, 0.0028138217, 0.0011745844, 0.017070733, -0.007350259, 0.021565078, 0.014376718, -0.0010669208, -0.0125828665, -0.011579086, 0.010096082, -0.0066897073, -0.010005418, -0.03390833, 0.039115034, -0.014311958, 0.022678949, 4.5655793E-4, 0.0032460946, -0.0107760625, 0.017770141, -0.010633591, 0.006362669, 0.023313597, -8.4187987E-4, -0.009610383, -0.009448483, 0.024142524, -0.01290019, -0.0034711354, 0.03351977, 0.04090241, 0.009707523, -0.017239109, 0.03460774, -0.012259066, 0.019855414, -0.030773947, 0.01536107, 0.035177626, -0.022912085, 0.022653045, -0.0051937513, 0.015723726, -0.024466325, 0.007551015, 0.025437724, -0.007188359, 0.018754493, 0.007777675, 0.0058737313, 0.0037010335, -0.025269348, -0.0054851715, 0.03287217, 0.01134595, 3.9017893E-4, 0.0021208897, -0.014661662, 0.022290388, 0.006618471, -0.0058510653, -0.016371327, -0.033364348, 0.02300275, 0.0028899147, 0.01254401, -0.01562011, 0.0011276334, 0.0032169526, 0.010406931, -0.010866727, -0.013962254, -0.0014490047, -0.020904524, 0.0052585113, -0.01814575, 0.02274371, 0.006420953, -0.045746457, 0.009804662, 0.027691372, 0.004591483, -0.0020982237, 0.018948773, -0.0013842448, 0.0011494899, -0.017770141, 0.0028931526, -0.019427998, 0.015697822, -0.0023928815, -0.009675142, 0.023171125, 0.0115855625, 0.007071791, -0.010905582, -0.0025612577, 0.026137132, -0.007920147, -0.028598012, 0.023481973, 0.026046468, -0.019997885, -0.010251506, 0.0017274728, 0.01846955, -0.053310424, 0.041394588, -6.7795615E-4, 0.014687566, 0.008062619, -0.0016084763, 0.006093915, 0.017537005, 0.0100248465, 0.0021484126, 0.011190526, -5.120087E-4, -0.024336804, -0.01406587, -0.018301174, 0.0037981735, -0.0036297976, -0.0013372938, -0.032820363, -0.007738819, 0.015594206, -0.029996827, -0.02839078, -0.007842435, -0.007013507, 0.02191478, 0.0023086937, -0.04616092, -0.029711884, 0.0014668138, 0.04310425, -0.020062646, 7.7023916E-4, 0.026486836, -0.033467963, -0.01581439, -0.0010361598, -0.16371326, 0.014855942, -0.0023653586, -0.020800909, 0.010147891, 0.0042288275, 0.009318963, 0.0025774476, -0.014558046, -0.008328135, 0.021228325, 0.027199196, -0.021059949, 0.021098806, 0.005060993, 0.021888876, -0.027173292, 0.0019444188, 0.034452315, 0.0052520353, 0.026396172, -0.016837597, 4.7598593E-4, 5.715069E-4, 0.03007454, 0.0034193275, -0.03680958, 0.012459822, 0.006793323, -0.008094999, -0.009694571, 0.006974651, 0.044632584, 0.009862946, 0.0051581333, 4.8974744E-4, 0.0013227228, 0.005154895, -0.01516679, 0.0044587255, 0.0030275297, 0.0036233214, 0.015969813, 0.008606602, -0.028546205, 0.020632533, 0.016449038, 0.012310875, -0.024751268, -0.015658965, 0.016824646, -0.01348303, 0.012757719, 0.006650851, 0.024207285, 0.023805773, -0.01361255, 0.022588285, 0.01270591, -0.011915838, -0.0010094463, -0.03124022, -0.008587175, 0.0048472853, 0.0027976315, 0.019065341, -0.01957047, 0.01685055, 1.2081786E-4, 0.006702659, 0.015594206, -0.03541076, -0.009655715, -0.021694597, 0.0048278575, -0.0063497173, -0.027069677, 0.0020674628, 0.005235845, -0.011935267, -0.017213205, 0.047300696, -0.0031003845, -0.0010515404, -0.008632507, 0.007751771, 0.01286781, -0.004678909, -0.034581836, -0.007952527, 0.03007454, -0.040099386, 0.0017371868, -0.02300275, -0.010517023, 0.0019217527, 0.012984378, 0.022963893, -0.011974122, -0.019194862, -0.010614162, -0.0033286635, -0.01393635, 0.012971426, -0.016474942, 0.02410367, 0.0078553865, 0.011838126, 0.02515278, 0.0060680113, 0.008133855, -0.01299733, 0.012589342, 0.0036880814, 0.019855414, 0.013962254, -0.008185663, -0.010653019, 0.02670702, -0.031680588, -0.017666526, -0.026279604, -0.0043648235, 0.030877564, -0.0055207894, -0.0022617427, -0.05709241, 0.013327606, -0.006420953, 0.026124181, 0.01608638, 0.03784574, 0.015063174, 0.024790125, -0.01060121, -0.013139802, 3.3776383E-4, 0.0015145743, -0.030126348, -0.014091774, 0.021629836, -0.026784733, -0.006340003, -0.019596374, -0.013625502, -7.1114564E-4, -0.0041543534, -0.0040151193, -0.016889406, -0.029271515, -0.02683654, 0.007279023, -0.02112471, 0.058750264, 0.01821051, 0.005747449, 0.030126348, -0.014027014, 0.0029676266, -0.019816557, -0.013457126, -0.013081518, -0.024751268, -0.010931486, 0.0027943936, -0.026292557, 0.019687038, -0.0037981735, 4.4967717E-4, -0.02359854, -0.026862444, 0.0052326075, -0.0018391837, 0.014441478, 0.0025531626, -0.0053394614, -0.03201734, -0.0013105803, -0.028468492, -0.024660604, 0.018637925, -0.0024835456, 0.0042612073, 0.01853431, -0.021940686, 0.009390199, -0.0036395115, 0.0025029737, -0.0053459373, 0.046394058, 0.009785235, 0.023715109, -0.008561271, -0.010368074, 0.013366462, 0.0035585614, 0.005067469, 0.034478217, -0.010251506, 0.032613132, -0.018573165, -0.022122012, -0.038286105, -0.037534893, 0.01704483, -0.013793878, -0.006767419, -0.0213967, 0.007551015, -0.0084770825, 0.009798187, 0.017135493, -9.6816185E-4, 0.0049120453, 0.016500846, 0.017990325, 0.008846215, 7.8076264E-4, 0.026888348, -0.01341827, -0.009785235, -0.013923398, -0.007894243, -0.014337862, 0.013819782, -0.005647071, 0.00885269, -0.032302283, -0.07242757, 0.01510203, 0.007117123, 0.0040474995, -0.009053446, -0.0029935306, -0.007466827, -0.009053446, -0.0032460946, -0.006877511, -0.020800909, 0.011753938, 0.006903415, -3.2076432E-4, -0.03054081, -8.297374E-4, 0.03201734, 0.015309262, 0.01134595, 0.009079351, -0.0011608228, 0.010504071, -0.005964395, 0.018197557, -0.007835959, 0.025580196, -1.9225622E-4, 0.019013533, -0.007680535, -0.018637925, -4.002977E-4, -0.033364348, 0.017977374, 0.023507876, -0.012045358, -0.022122012, -0.0044878675, 0.014817086, 0.01523155, 0.009461435, -0.020166261, -0.03608427, 0.044192217, 0.012854858, -0.025852188, -0.010096082, -0.024919644, 0.011728034, 0.02067139, -0.0045299614, 0.01432491, 0.014208342, 0.006139247, 0.0039503593, 0.0027037296, -0.020166261, 0.014441478, 0.010607687, 0.019130101, -0.012291446, 0.02326179, 0.021293085, 0.024207285, 0.0053815553, 0.01141071, 0.012893714, -0.0013996253, -0.008755551, 0.010808443, -0.01222021, -0.015801437, 0.020567773, -0.0055045993, 0.029245611, 0.015658965, -0.0016724268, 0.018935822, -0.021785261, -0.019453902, 0.03797526, 0.0039665494, 0.017187301, -0.010374551, 0.014622806, 0.01247925, 0.007188359, -0.021888876, -0.014985462, -0.028960668, 0.019440949, -0.031913724, -0.0024252618, 0.019168958, 0.020425301, 0.021824118, 0.015633062, 0.017575862, -0.014674614, 0.02385758, 0.02839078, -0.0052941293, 0.009811139, -0.01652675, -0.0037496034, -0.0054268874, -0.0014376718, -0.0153869735, -0.020826813, 0.0060032513, 0.010866727, -0.008120903, 0.013495982, -0.02469946, 0.028079933, -0.011061006, -0.0024803076, -0.0020755576, -0.025826285, -0.017498149, 0.02508802, 2.102676E-4, 0.006994079, 0.013845686, -0.0184825, 0.005355651, -0.006670279, -0.01150785, -0.006722087, 0.019220766, 0.0024155476, 0.0061554373, -0.0030663856, -0.008561271, -0.007525111, -0.016980069, 0.022381052, 0.009824091, 0.02436271, -0.039374076, 0.037042715, 0.0049541392, -0.0042773974, 0.027017869, -0.019298477, -0.0011405853, 0.014506238, 0.010063702, 0.006420953, -0.0041932096, -0.006087439, 0.004338919, -0.008885071, -0.016358374, -0.030281771, -0.022601238, -0.005300605, 0.021733453, -0.03020406, -0.0013170564, 0.034840874, -0.006812751, 0.014830038, 0.010232079, -0.021603933, -0.02774318, 0.023430165, -0.0032250476, -0.0017274728, -0.022963893, -0.0034873255, 0.012757719, 0.011689179, -0.0037722695, -0.009066399, -0.0035715136, -0.006760943, 0.013703214, 0.0011090148, 0.026227796, 8.9044985E-4, 0.006272005, -0.02515278, -0.005857541, 0.025981707, -0.006194293, -0.0065375213, 0.0109638665, -0.0057150694}}}, model:"text-embedding-ada-002-v2", usage:{total_tokens:9, prompt_tokens:9}}

★Click Here to Open This Script 

(Visited 78 times, 1 visits today)
Posted in Natural Language Processing REST API Text | Tagged 12.0savvy 13.0savvy ChatGPT | Leave a comment

AppleScriptによるWebブラウザ自動操縦ガイドをmacOS 13対応アップデート

Posted on 2月 22 by Takaaki Naganoya

SafariやGoogle Chromeなど7つのmacOS用Webブラウザを操作するAppleScriptの書き方と有用な実例を紹介する電子書籍「AppleScriptによるWebブラウザ自動操縦ガイド」をアップデートしたv1.3を公開しました。ページ数も317から330ページに増加。macOS 12, Monterey & 13 Ventura, Apple Silicon Mac対応です。

→ 販売ページ

目次

1章 めんどうな操作を自動化しよう!
人間の手で操作して情報を集めたり、データ入力するのは非効率。スクリプトから操作して自動操作

2章 スクリプトエディタの使い方
AppleScript専用のスクリプトエディタの使い方など、基礎的な内容をご紹介。

3章 WebブラウザをAppleScriptから動かそう
macOS用Webブラウザの大半はAppleScriptから操作可能。AppleScript対応は必須の機能!

4章 Webブラウザの情報を取り出そう
Webブラウザ自体が大量の情報を管理しています。まずは、ブラウザの情報を調べてみましょう。

5章 指定URLをオープンしよう
誰にでも確実に行える操作です。かならず経験しておきましょう。URLをオープンした後が大事です。

6章 コンテンツをキャプチャして保存しよう
表示内容を変化しないデータや、再利用可能なデータとして残しておくことは、重要な処理です。

7章 Webコンテンツにアクセスしよう
HTML内の操作対象にアクセスするための、さまざまなアプローチをご紹介

8章 Webコンテンツを画面部品として操作しよう
画面上の部品と同様にWebコンテンツにアクセスして強引に操作する「奥の手」GUI Scripting

9章 ログイン、ログアウトしてみよう
ユーザー登録が必要なWebサイトの処理を行うために必須の作業です。意外とクリアしにくい箇所

10章 データをダウンロードして処理しよう
直接ダウンロードできないファイルのダウンロード完了を検出して、ファイル処理しよう! ダウンロード後にファイル整理したりファイル名を変更したり

11章 仮想ディスプレイでユーザーの誤操作を防ごう
ユーザーからの操作をガードするために、仮想ディスプレイを用意してWebブラウザを表示! 画面上から強引にScriptで動かすと、ユーザーの誤操作が一番の大敵

12章 さまざまな実行環境を知ろう
AppleScriptにはいろいろな実行環境があって、環境ごとにできる/できないことがあります。時間と気持ちに余裕のある時にでも読んでおくとよいでしょう。

13章 実例:Quoraの統計データを取得しよう
実際に、Quoraのアクセス情報ページにアクセスし、自分の投稿情報を取得してみよう!

14章 さまざまな技術資料。興味があったら読んでね
アプリケーション・オブジェクトの指定方法/AppleScript用語辞書の確認方法/Webブラウザの基礎的なScripting/Google Chrome系のWebブラウザのsdef/AppleScriptの歴史/AppleScriptのエラーコード表/各Webブラウザの用語辞書の変更履歴/AppleScript予約語一覧

(Visited 29 times, 1 visits today)
Posted in Books news | Tagged 12.0savvy 13.0savvy Brave Browser Google Chrome Google Chromium Microsoft Edge Opera Safari Vivaldi | Leave a comment

Dockアイコンにプログレスバーを追加 v3

Posted on 2月 17 by Takaaki Naganoya

実行プログラムのDock上のアイコンにプログレスバーを描画して、プログレスバーの内容をアニメーションするAppleScriptです。オリジナルはedama2さんが書かれたものです。

以前のバージョンはmacOS 10.12以前の時代に書かれたものだったので、macOS 10.13以降の形式に書き換えました。

実行プログラムが何であっても、Dockにアイコンが表示されるかぎりはアイコンにプログレスバーを描画します。スクリプトエディタ、Script Debugger、AppleScriptアプレット、Script DebuggerのEnhanced Appletなどなど。

ただし、Dockにアイコンが表示されない種類のAppleScript実行プログラム(例:スクリプトメニュー など)については、プログレスバーは表示されません。

choose colorコマンドで色選択しているのは、あくまでもデモ動作のためであり、あらかじめRGB値を指定しておけばその色でプログレスバーを描画します。

プログラム中でプログレスバーの表示ループ中にてdelayコマンドで時間待ちしているのは、目で見てわかるようにしているだけで、本来この数値はもっと小さい値でかまいません(ただし、表示のためにdelayコマンドは必須です)。

AppleScript名:Dockアイコンにプログレスバーを追加 v3.scptd
use AppleScript
use scripting additions
use framework "Foundation"
use framework "AppKit"

property NSApp : a reference to current application’s NSApp
property NSColor : a reference to current application’s NSColor
property NSImage : a reference to current application’s NSImage
property NSGradient : a reference to current application’s NSGradient
property NSZeroPoint : a reference to current application’s NSZeroPoint
property NSBezierPath : a reference to current application’s NSBezierPath

on run
  set aASCol to choose color
  
set aCocoaList to retCocoaColorList(aASCol, 65535) of me
  
set aCol to makeNSColorFromRGBAList(aCocoaList)
  
  
set max to 100
  
repeat with num from 1 to max
    my progDockTile(max, num, aCol)
    
delay 0.05
  end repeat
  
  
#アイコンを元に戻す
  
NSApp’s setApplicationIconImage:(NSImage’s imageNamed:"NSApplicationIcon")
end run

#Dockアイコンにプログレスバーを追加
on progDockTile(max, current, strartColor)
  set appIcon to NSImage’s imageNamed:"NSApplicationIcon"
  
set iconSize to appIcon’s |size|()
  
  
tell (NSImage’s alloc()’s initWithSize:iconSize)
    
    
lockFocus()
    
    
appIcon’s dissolveToPoint:(NSZeroPoint) fraction:1.0
    
set n to (iconSize’s width) / 16
    
    
#プログレスバーの長方形
    
set myRect to current application’s NSMakeRect(n / 2, n, n * 15, n * 1.6) –>{origin:{x:4.0, y:8.0}, |size|:{width:120.0, height:12.800000190735}}
    
    
tell (NSBezierPath’s ¬
      bezierPathWithRoundedRect:myRect ¬
        xRadius:(myRect’s item 2’s item 2) / 2 ¬
        
yRadius:(myRect’s item 2’s item 2) / 2)
      
      (
NSColor’s colorWithWhite:1.0 alpha:0.4)’s |set|() –>背景色
      
fill()
      
      
NSColor’s whiteColor()’s |set|() –>枠色
      
stroke()
    end tell
    
    
if current is greater than 0 then
      if current is greater than max then set current to max
      
set myRect’s item 2’s item 1 to (myRect’s item 2’s item 1) / max * current
      
      
tell (NSBezierPath’s ¬
        bezierPathWithRoundedRect:myRect ¬
          xRadius:(myRect’s item 2’s item 2) / 2 ¬
          
yRadius:(myRect’s item 2’s item 2) / 2)
        
        
–set strartColor to NSColor’s colorWithRed:0.15 green:0.55 blue:1 alpha:0.8
        
set endColor to strartColor’s shadowWithLevel:0.7
        
set grad to NSGradient’s alloc()’s initWithStartingColor:strartColor endingColor:endColor
        
grad’s drawInBezierPath:it angle:270.0
      end tell
    end if
    
    
unlockFocus()
    
    
NSApp’s setApplicationIconImage:it
  end tell
  
  
return (current + 1)
end progDockTile

–Convert "choose color" RGB list (0-65535) to Cocoa color RGBA Array (0.0-1.0)
on retCocoaColorList(aColorList, aMax)
  set cocoaColorList to {}
  
repeat with i in aColorList
    set the end of cocoaColorList to i / aMax
  end repeat
  
set the end of cocoaColorList to 1.0
  
return cocoaColorList
end retCocoaColorList

on makeNSColorFromRGBAList(colList)
  copy colList to {redValue, greenValue, blueValue, alphaValue}
  
set aColor to NSColor’s colorWithCalibratedRed:redValue green:greenValue blue:blueValue alpha:alphaValue
  
return aColor
end makeNSColorFromRGBAList

★Click Here to Open This Script 

(Visited 54 times, 1 visits today)
Posted in GUI | Tagged 12.0savvy 13.0savvy Dock | Leave a comment

新発売:AppleScript基礎テクニック集(29)セキュリティ機能解除

Posted on 2月 15 by Takaaki Naganoya

Piymaru Softwareによる電子書籍の72冊目、「AppleScript基礎テクニック(29)セキュリティ機能解除」を発売しました。PDF 36ページ+サンプルScript Zipアーカイブで構成されています。

→ 販売ページ

macOS上の主要アプリケーション、FileMaker Pro、ミュージック.app、Webブラウザ、iWork(Keynote、Pages、Numbers)、CotEditorときて、ご要望の多かった「メール」(Mail.app)についてのScripting本です。macOS 13.1+Mail.app v16対応。PDF 369ページ+サンプルScript Zipアーカイブで構成されています。

macOS 10.7以降、それ自体の機能を制限するための「セキュリティ機能」が強化されるようになりました。つまり、機能を「制限する機能」です。macOS 10.10以降になると、セキュリティ機能の制約はAppleScriptにも及ぶようになり、デフォルトの状態では各種機能を動作できない設定状態でOSがリリースされるようになりました。

AppleScriptからmacOSのフル機能を利用するためには、各種セキュリティ機能の解除を行う必要があるわけです。AppleScriptからアプリケーションを操作しようとすると、「プライバシーとセキュリティ」>「オートメーション」などで実行側のプログラム(AppleScriptアプレットなど)に対して実行許可が必要です。

この解除方法を知らなければ、AppleScriptの制限解除が行えないわけで、「Scriptが動かなくなった!」「Scriptが壊れた!」と騒いでいる人を見かけますが、ほとんどがこれです。そして、Appleがこうした説明をしないため、知識や情報を持たない人はOSの機能を十分に発揮させられません。macOSの足枷を外して、本来のパワーを取り戻すための1冊です。もちろん、危険なことには手を出しません。

目次

macOSのセキュリテイ機能とAppleScriptの制限解除

初期状態のままだと最新の環境でASが動かない
macOSのバージョンとセキュリティ機能の変化
macOS 12までの「セキュリティとプライバシー」
macOS 13からの「プライバシーとセキュリティ」
①アクセシビリティ
②フルディスクアクセス
③ファイルとフォルダ
④オートメーション
オートメーションの認証状態を取得
アクセシビリティの認証状態をScriptで確認

AppleScriptの実行プログラム=ランタイム環境を確認

AppleScriptアプレットを実行する場合には
実行環境1:スクリプトエディタ
実行環境2:スクリプトメニュー
実行環境3:Automator
実行環境4:ショートカット.app
実行環境5:/usr/bin/osascript
AppleScript 各ランタイム環境情報(1/2)
AppleScript 各ランタイム環境情報(2/2)

その他のセキュリティ関連設定

Image Eventsが使えない!
ドロップレットでファイルを受信できない!
Safari でAppleScriptのコマンドがエラーに!
Safari 10以降のdo JavaScript設定

(Visited 29 times, 1 visits today)
Posted in Books Security | Tagged 12.0savvy 13.0savvy | Leave a comment

Keynoteの表の選択中のセルのデータをDeepLで翻訳して書き戻す

Posted on 1月 31 by Takaaki Naganoya

Keynoteの最前面の書類中の、現在表示中のスライドの表の選択中のセル中のテキストを取得してDeepLのREST APIを呼び出して指定言語に翻訳し、表のセルに翻訳後のテキストを書き戻すAppleScriptです。

DeepLのREST API呼び出しのためには、DeepL SE社のWebサイトで「DeepL API Free」(無料コース)か「DeepL API Pro」プランにサインアップして、API Keyを取得して、プログラムリスト中に記入したうえで実行してください。


▲実行前。Keynote書類上の表の翻訳対象のセルを選択して実行


▲実行後。Keynote書類上の表の翻訳対象のセルをに翻訳後の内容をストア

実際に使ってみると、けっこう翻訳に時間がかかるのと、一度翻訳した同じフレーズを再度翻訳させるのはコストがかかるため、ローカルに「翻訳キャッシュ」を作って、翻訳ずみの内容を再翻訳しないように工夫する必要がありそうです。

AppleScript名:Keynoteの表の選択中のセルのデータをDeepLで翻訳して書き戻す.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2023/01/30
—
–  Copyright © 2023 Piyomaru Software, All Rights Reserved
—

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

property NSString : a reference to current application’s NSString
property NSCountedSet : a reference to current application’s NSCountedSet
property NSJSONSerialization : a reference to current application’s NSJSONSerialization
property NSUTF8StringEncoding : a reference to current application’s NSUTF8StringEncoding

set myAPIKey to "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
set myTargLang to "EN" –翻訳ターゲット言語

set aTableDat to returnSelectedTableCellDataOnCurrentSlide() of me
–> {"プロパティ項目", "データ型", "読み/書き", "内容(サンプル)", "説明"}

set nList to {}
repeat with i in aTableDat
  set j to contents of i
  
set tRes to translateWithDeepL(j, myAPIKey, myTargLang) of me
  
set the end of nList to tRes
end repeat

–表に翻訳した内容を書き戻す
storeSelectedTableCellDataOnCurrentSlide(nList) of me

on storeSelectedTableCellDataOnCurrentSlide(sList)
  tell application "Keynote"
    tell front document
      tell current slide
        try
          set theTable to first table whose class of selection range is range
        on error
          return false –何も選択されてなかった場合
        end try
        
        
tell theTable
          set cList to every cell of selection range
          
if (length of cList) is not equal to (length of sList) then error
          
          
set aCount to 1
          
repeat with i in cList
            set j to contents of i
            
tell j
              set value of it to (contents of item aCount of sList)
            end tell
            
set aCount to aCount + 1
          end repeat
        end tell
      end tell
    end tell
  end tell
end storeSelectedTableCellDataOnCurrentSlide

on returnSelectedTableCellDataOnCurrentSlide()
  tell application "Keynote"
    tell front document
      tell current slide
        try
          set theTable to first table whose class of selection range is range
        on error
          return false –何も選択されてなかった場合
        end try
        
        
tell theTable
          set vList to value of every cell of selection range
          
set cCount to count of column of selection range
          
set rCount to count of row of selection range
          
          
–複数行選択されていた場合にはエラーを返すなどの処理の布石
          
return vList
        end tell
      end tell
    end tell
  end tell
end returnSelectedTableCellDataOnCurrentSlide

–DeepLのAPIを呼び出して翻訳する
on translateWithDeepL(myText, myAPIKey, myTargLang)
  set sText to "curl -X POST ’https://api-free.deepl.com/v2/translate’ -H ’Authorization: DeepL-Auth-Key " & myAPIKey & "’ -d ’text=" & myText & "’ -d ’target_lang=" & myTargLang & "’"
  
try
    set sRes to do shell script sText
  on error
    error
  end try
  
  
set jsonString to NSString’s stringWithString:sRes
  
set jsonData to jsonString’s dataUsingEncoding:(NSUTF8StringEncoding)
  
set aJsonDict to NSJSONSerialization’s JSONObjectWithData:jsonData options:0 |error|:(missing value)
  
  
set tRes to aJsonDict’s valueForKeyPath:"translations.text"
  
if tRes = missing value then
    set erMes to (aJsonDict’s valueForKey:"message") as string
    
error erMes
  else
    return contents of first item of (tRes as list)
  end if
end translateWithDeepL

★Click Here to Open This Script 

(Visited 31 times, 1 visits today)
Posted in REST API shell script Text | Tagged 12.0savvy 13.0savvy | Leave a comment

2022年に書いた価値あるAppleScript

Posted on 12月 27, 2022 by Takaaki Naganoya

2022年に使用していたmacOS:macOS 12→13

毎年行なっている、Piyomaru Softwareが書いたAppleScriptの1年を振り返る記事の2022年版です。

→ 2018年に書いた価値あるAppleScript
→ 2019年に書いた価値あるAppleScript
→ 2020年に書いた価値あるAppleScript
→ 2021年に書いた価値あるAppleScript

2022年も大変な1年でした。macOSやApple純正アプリケーションのバグが発生したり治ったりのジェットコースター状態。macOS 13.0についても「冗談だよね?」という出来で、

 「もう、OSがアップデートされて半年ぐらい待たないとリリース状態にならないのかも?」

と感じるものです。

13.1でずいぶんまともになりましたが、13.1の出来になってからリリースすべきなのでは? というところ。

たいした追加機能がない割にバグがその数十倍もてんこもりについてくるのは、どうなんでしょう? Appleは機能を開発しているのではなく、もはや「いやがらせのための機能」や「新たなバグ」を開発しているメーカーであるように感じます。β版の段階で開発者/ユーザーが検証して「この新たな嫌がらせの機能は納得できない」とフィードバックしないと、延々と嫌がらせのための機能が増えてくるので、油断できません。

macOS 13のシステム設定も、警告音のフォルダにサウンド以外のAppleScript書類を入れても警告音一覧にそれが出てきてしまうので(さすがに再生はできない)初心者が作るへっぽこアプリケーション並みの作りになっていることが見て取れます。

本を書きまくった1年?

今年執筆した書籍はおよそ、41冊。いま書いている「Mail.app Scripting Book With AppleScript」が年内に書きあがれば(無理無理無理無理)42冊。

ピークの4月は1か月間に8冊。3日に1冊のペースで出していました。感想やら何やら事前に読んでいただいているEdama2さんのご協力に感謝しています。本当にありがとうございます。

「基礎テクニック集」は、今年あらたに立ち上げた書籍シリーズで、「こういうのがないとダメなんじゃないか?」という議論の中から生まれた、基礎を重点的に解説する本です。まだ、書いていない積み残したテーマがあるので、続く感じでしょう。

「実践テクニック集」は、前述の「基礎テクニック集」ではおさまりきらない大きなテーマを扱うシリーズとして立ち上げました。「GUI Scripting」はまとめておくべき大きなテーマであり、方向性やノウハウやツールの使い方など(UI Browserなど)を徹底的に紹介しています。

2022年に書いた価値あるAppleScript

そんなわけで、本ばかり書いていたので毎日KeynoteやPagesばかり使っており、これらのアプリケーションを操作するAppleScriptが必要になったら書いて作業を効率化するという繰り返し。本数はそれほど多くないものの、けっこう強力なものがそろっています。

一方で今年書いたAppleScriptで価値あるもの……といったときに、月ごとにリストアップする形式に無理を感じるようになってきたので、毎月1本といった固定形式にせず、適宜リストアップします。

・AS関連データの取り扱いを容易にする(はずの)privateDataTypeLib
オブジェクトからデータを取り出すのにデータアクセス文字列で指定するという試みです。この手の仕組みがないと、プログラムが冗長になりがちなので用意してみようかというお話しです。

・Bundle IDで指定したアプリケーションのSDEFからコマンドを抽出テスト(指定コマンドのコマンド属性取り出し)
・Bundle IDで指定したアプリケーションのSDEFからオブジェクトを抽出
・Bundle IDで指定したアプリケーションのSDEFからXPathで指定したClassにアクセス v2
アプリケーション内蔵のAppleScript用語辞書を解釈して、Scriptを自動生成するための試みです。割とできるようになるんじゃないかと思っていますが、まだ基礎実験を行なっているだけの状態です(そういうの多いな!)

・Keynoteの表で選択中のセルの文字列長さを一覧表で表示
自分の書いた本の既刊分の説明文をKeynoteの表に入れ、文字が多いとか少ないといった「ゆらぎ」を調べるためのものです。決められたスペースに入れなくてはならないので、この手の細かい作業は割と発生し、こうした確認用Scriptをいったん作っておけば次回からはきわめて短い時間で作業できます。

・Keynote上でテキストアイテムとn重のシェープの重なりを検出 v2
ある意味、Cocoaの機能とGUIアプリケーションの機能をブレンドした内容で、GUIアプリケーションの機能だけでは実現できなかった処理です。矩形オブジェクトが2重とか3重に重なっている場合に検出するというのは、半透明のオブジェクトを重ねて何かを表現している中で生まれたものです。

・Keynote書類中のスライドのトビラページを推測する
Keynoteのマスターページの名前の分布から扉ページを推測するというものです。自分の作る本の傾向を反映させたもので、どの人でも普遍的に使用できるわけではありませんが、、、。

・RectangleBinPackを用いて2D Bin Packを解く v2.3
2D BinPackは、指定の矩形エリア内に指定の複数のオブジェクトを最適化配置して詰め込むもので、KeynoteのようなGUIアプリケーションに対して実行できるのは、非常に効果的です。

・Safariで表示中のYouTubeムービーのサムネイル画像を取得
本当は指定の再生ポジションのサムネイル画像を取得したかったのですが、まだそこまで研究が進んでいません。

・Keynoteの最前面の書類の現在のスライド上の表オブジェクトの重なり合い(2つ以上対応)を検出 v3
これは、書籍に添付しているコマンド表が重なって配置されるという「事故」から、それを検出するScriptを作成したものです。Keynoteの表オブジェクトだけでなく、他のアプリケーションの他のオブジェクトの重なり合わせも検出できることでしょう。

・書籍フォルダの階層をさかのぼって、ツメに掲載する最大チャプターを推測 v2
Pages書類が入っているフォルダの親フォルダをたどって、そのフォルダに記入されている章の数字から最大のものを計算することで、ツメ(ページ端に記載するインデックス)の大きさを変更するものです。ツメをつけると可読性が上がる本がある一方で、ツメの作成や変更を手作業で行うなんて耐えられません。そういうものこそAppleScriptで自動処理させるべきです。

・リストに入れたテキストで、冒頭に入ったマルつき数字をリナンバーする
丸つき数字のリナンバーは、つまらない内容の割に手間がかかる作業であり、これも手作業を撲滅したい内容の上位に入ってくるものです。

・与えられた自然言語テキストから言語を推測して、指定の性別で、TTSキャラクタを自動選択して読み上げ
この手の処理は、AppleScriptのコマンドレベルで普通にできてほしい内容です。ないので自分で書きましたが、macOS 13でText To SpeechキャラクタのID周りに手が入って、これも書き直さないといけないかもしれません。

・Intel MacとApple Silicon Macの速度差〜画像処理
内容はもちろんタイトルどおりですが、これでM1を集積したM1 ProであるとかM1 Ultraの処理性能がメーカー側が言うほどリニアに向上しているわけではないことがわかりました。つまり、M1よりもそれらの上位CPUの方が「処理が遅くなるものもけっこうある」ということです。ここから、M1世代でM1を集積したMac Proが出たら、相当にM1よりも遅い処理が出てくるのでは? と噂していたものですが、作ってはみたもののキャンセルされたようなので、見立て通りといったところだったのでしょう。

2022年の出来事(macOSのバグ以外)

UI Browser 3の開発と販売が終了し、LateNight Softwareに移管された、というのが1つの大きな流れです。Swiftで書き直されたUI Browser 4についてはgithub上でオープンソースで開発が継続されています。

そして、Font Book.appがMac Catalystのアプリケーションに変更され、それにともなってAppleScript用語辞書が削除されました。これが復活するのかどうかは不明ですが、ここに新たに「Catalyst堕ち」という言葉が爆誕。Mac Catalyst化=機能低下バージョンという方針が明らかになってきました。

今年参加したコンテストはFileMaker Proの「バカスタム App選手権」。これに入賞しています。

(Visited 103 times, 1 visits today)
Posted in news | Tagged 12.0savvy 13.0savvy | Leave a comment

新発売:CotEditor Scripting Book with AppleScript

Posted on 12月 11, 2022 by Takaaki Naganoya

Piyomaru Software Booksの69冊目。「CotEditor Scripting Book with AppleScript」を発売しました。PDF 343ページ+サンプルScriptZipアーカイブ で構成されています。

→ 販売ページ

アプリケーションのすべてのScriptingをわかりやすく詳細にまとめた徹底解説シリーズの第5弾。

CotEditorは(起動、動作が)速い、うまい、フリー、と3拍子そろった、Macユーザー定番のテキストエディタです。

macOS専用に作られているため、その分、macOSならではの機能を活かす方向に全振りした作りになっています。

そんなCotEditorはもちろんAppleScriptに対応しており、さまざまな作業の部品としてCotEditorを利用したり、CotEditor自体の機能をAppleScriptで追加することもできます。macOS 12以降に対応。

■初級

・スクリプトエディタを起動しよう

スクリプトエディタを起動しよう!
スクリプトエディタのヘルプ
色設定を変えてみよう!
スクリプトを入力してみよう
スクリプトを保存しよう
スクリプトを実行しよう(1/3)
スクリプトを実行しよう(2/3)
セキュリティとプライバシー
プライバシーとセキュリティ(13.x以降)
セキュリティとプライバシー>プライバシー
プライバシーとセキュリティ(macOS 13)

・CotEditorを起動しよう

CotEditorを指定
CotEditor.appを起動
CotEditor.appを終了
CotEditorのAppleScript用語辞書の調べ方
メニュー項目や画面強制操作の調べ方
CotEditorの詳細仕様について

・CotEditor自体の情報を取得しよう

CotEditorの名前を取得
CotEditorのバージョンを取得
CotEditorのプロパティ項目と内容

・オープン中の書類へのアクセス

CotEditorでオープン中の書類へのアクセス
最前面の書類、ウインドウにアクセス
documentの属性情報にアクセス
windowの属性情報にアクセス
ウインドウ関連の操作で「できない」こと

・書類の選択部分へのアクセス

selection=選択中のテキスト
selection自体のプロパティ
selection内容のテキストの取得
selection内容の書き換え
selectionの作成

・書類のスクロールとジャンプ

書類のスクロール①
書類のスクロール②
書類の指定行にジャンプ
書類の乱数行にジャンプ

・ウインドウの操作

ウインドウの属性値へのアクセス
指定ウインドウを最前面に表示
指定ウインドウの表示状態を変更
指定ウインドウをズーム表示
参考:最前面のウインドウをフルスクリーン表示
指定ウインドウのサイズを変更

・CotEditor内蔵コンソールへの文字列出力

コンソールに文字列を出力

・内蔵/OS搭載スクリプトメニューからの操作

2つのScript Menu環境
CotEditor内蔵スクリプトメニュー
macOS搭載標準スクリプトメニュー
各スクリプトメニューの技術仕様

・AppleScriptからCotEditorを操作するパターン

■中級

・ファイルのオープン

ファイルを指定して書類をオープン
複数のファイルを指定して書類をオープン
コラム「CotEditorが使用するパス表現」

・ファイルの保存

書類を指定パスに保存
書類を新規作成して本文を設定して指定パスに保存
保存済み書類に変更が加わっていたら保存

・ファイルのクローズ

書類をクローズ(with saving)
書類をクローズ(without saving)
書類をクローズ(saving ask)
新規書類をクローズ

・各種文字操作(選択範囲の操作)

change case
change kana
change roman width
shift right
shift left
move line up
move line down
sort lines
delete duplicate line
comment out
uncomment
smarten quotes
straighten quotes
smarten dashes
normalize unicode

・各種文字操作(document全体の操作)

find(1/2)
find(2/2)
replace
string

・タブ、改行コードの取り扱い

改行コードの変更タブ幅の変更
文字コードの指定
convert
reinterpret

・書式つきテキスト対応機能

CotEditorの書式つきテキスト対応機能
書式つきテキスト機能にAppleScriptからアクセス

・AppleScript非対応機能を呼び出す

AppleScriptで操作可能な範囲
GUI Scripting:メニューなどを強制操作①
GUI Scripting:メニューなどを強制操作②
GUI Scripting:メニューへのアクセス
指定ウインドウを最前面に移動

・プリントアウト

CotEditorからの印刷出力(macOS 13)
AppleScriptによるプリントアウト
GUI Scriptingによるプリントアウト①
GUI Scriptingによるプリントアウト②
GUI Scriptingによるプリントアウト③
GUI Scriptingによるプリントアウト④
GUI Scriptingによるプリントアウト⑤

■上級

正規表現
正規表現が使えるAppleScriptコマンド
findコマンド+正規表現(GUI側との対応)
replaceコマンド+正規表現(GUI側との対応)
replace サンプル①
replace サンプル②
replace サンプル③
replace サンプル④

・オープン時に縦/横書きを強制できる書類仕様

xattrコマンドで強制的に縦書き表示

・文字数のカウント

CotEditorの文字数カウント機能
AppleScriptの文字カウント

・内蔵スクリプトメニューの独自仕様

フォルダ階層構造がそのまま反映される
内蔵スクリプトメニューの独自機能
メニュー上の並び順を指定
メニュー上の区切りセパレータ表示指定
キーボードショートカットの指定
Scriptをメニューに出さない(非表示設定)

・CotEditorのAppleScript関連機能のバグ(v4.4.2)
・高度なサンプル集

AppleScriptで操作可能な範囲
最前面のウィンドウをフルスクリーン表示(1/2)
最前面のウィンドウをフルスクリーン表示(2/2)
選択範囲のテキストをhexdump(1/2)
選択範囲のテキストをhexdump(2/2)
選択範囲のカンマ区切りテキストをNumbersへ(1/2)
選択範囲のカンマ区切りテキストをNumbersへ(2/2)
選択範囲のテキストの文字比率グラフを表示(1/8)
選択範囲のテキストの使用文字比率のグラフ表示(2/8)
選択範囲のテキストの使用文字比率のグラフ表示(3/8)
選択範囲のテキストの使用文字比率のグラフ表示(4/8)
選択範囲のテキストの使用文字比率のグラフ表示(5/8)
選択範囲のテキストの使用文字比率のグラフ表示(6/8)
選択範囲のテキストの使用文字比率のグラフ表示(7/8)
選択範囲のテキストの使用文字比率のグラフ表示(8/8)

・便利な他のプログラムや周辺機器

さまざまなAppleScript呼び出しプログラムから操作①(1/2)
さまざまなAppleScript呼び出しプログラムから操作①(2/2)
さまざまなAppleScript呼び出しプログラムから操作②
さまざまなAppleScript呼び出しプログラムから操作③
さまざまなAppleScript呼び出しプログラムから操作④

■資料集

・CotEditorのAppleScript用語辞書解説
・CotEditorのAppleScript用語の変遷
・CotEditor&AppleScript Q&A
・AppleScript mini Reference
・macOS搭載 AppleScript関連ドキュメント
・AppleScript関連の情報源
・macOSバージョンとAppleScriptの動向
・AppleScript予約語一覧
・サードパーティ製FrameworkやAppleScript Librariesを呼ぶ
・エラーコード表

(Visited 86 times, 1 visits today)
Posted in Books news | Tagged 12.0savvy 13.0savvy CotEditor | Leave a comment

クリップボードに入った書式つきテキストをプレーン化する「PlainerText」

Posted on 12月 10, 2022 by Takaaki Naganoya

macOS 11以降用の常駐ツール、クリップボードに入った書式つきテキストをプレーンテキスト化する「PlainerText」を開発、販売を開始しました(macOS 11以降)。

起動すると常駐し、メニューバー右側のステータスバー・エリアに「P」の絵文字を表示します。クリップボードを0.5秒ごとに監視し、スタイル付きテキストが入っていた(スタイル付きテキストをコピーした)場合にはプレーンテキストに変換して、beep音を鳴らします。

–> Play Demo1 Movie

–> Play Demo2 Movie

–> Download Trial Version (Work for 10 minutes)

PlainerTextはBOOTHで500円でダウンロード販売しています。

また、動作内容がわからないと安心できないという人向けに、ソースコードおよび詳細なソースコード解説書を別途販売中です。

(Visited 50 times, 1 visits today)
Posted in news PRODUCTS | Tagged 11.0savvy 12.0savvy 13.0savvy | Leave a comment

Finderの隠し命令openVirtualLocationが発見される

Posted on 11月 20, 2022 by Takaaki Naganoya

Twitter上で@usagimaruma氏がレポートしたところにより、FinderにSiri用の隠しAppleScriptコマンド「openVirtualLocation」が存在していることが明らかになりました。

ドキュメントに載っていないFinder AppleScriptの命令を見つけた。tell構文でFinderに対して 'openVirturalLocation "AirDrop"' みたいにすると、AirDropやiCloud Driveのウインドウを直接開ける。 pic.twitter.com/SZHb8c14T7

— usagimaru ⌘ (@usagimaruma) November 19, 2022

tell application "Finder"
	openVirtualLocation "AirDrop"
end tell

/System/Library/CoreServices/Finder.app/Contens/Applications の下にある、

といった小型アプリケーションが、上記のコマンドを利用して機能を呼び出しています。バイナリをダンプすると、”openVirtualLocation”コマンドの部分を生AppleEventsで記述してあり、少し不思議な雰囲気です。

早速、手元の環境でチェックしてみたところ、報告されたとおりに動きます。

hidden=”yes”に設定されているために、普通にFinderをsdefをスクリプトエディタで確認しただけでは表示されません。

過去にさかのぼって、どのバージョンのOSから使えるのかを確認してみたところ、

macOS 10.14:NG
macOS 10.15:NG
macOS 11.6:(Unchecked)
macOS 12.6:Exist
macOS 13.x:Exist

と、Siriの搭載とリンクしているというよりは、ショートカット.appの搭載とリンクしているように見えるので、macOS 11のFinderにこのコマンドは搭載されていないのではないか、と推測します。

(Visited 71 times, 1 visits today)
Posted in news | Tagged 12.0savvy 13.0savvy Finder Shortcuts Siri | Leave a comment

UI Browserがgithub上でソース公開され、オープンソースに

Posted on 10月 31, 2022 by Takaaki Naganoya

ちょっと驚きの展開です。Bill Cheesemanの引退にともない、その後の展開が不安視されていたUI Browserの新たな話が上がってきました。

たしかに、Bill Cheeseman引退後のUI Browserの「あり得る」ストーリーの1つとして、(v3.x系の)Open Source化は考えないではなかったのですが、まさかBill Cheeseman本人によりすべてSwiftで書き直されたもの(v4)が、あらためてオープンソース版として公開されるとは思いませんでした。

→ UI Browser 4 on github

公開されているのは、現行のUI Browser v3.0.2よりも新しい「v4」であり、完成したものではないようです。一応、興味があったのでProjectをダウンロードしてXcodeでビルドしてみましたが、UI Browser 4を起動することはできませんでした(ビルドは通ったが、起動途中で止まる)。

PFAssistiveFrameworkなどの心臓部分もすべてSwiftで描き直されているものの、「AccessibleElement.swift」が空行を含めてわずか570行程度であったりと、その機能から推測される(巨大な)コード規模とかけ離れた内容になっていることから、「手を付けられる範囲で手をつけただけ。完成品というレベルのものではない」という印象を受けます。

ただ、作り方が「ゼロから作り直した」のではなく、「C++のプログラムを順次翻訳している最中」に見えるため、これからも順次C++からSwiftに翻訳していくのかもしれませんし、そうではないのかもしれません。

v4が動くところまで行くのに、年単位で時間がかかりそうに見えます。

このようにちゃんと引き継ぎが行われるというのは、珍しいことであり……自分だったら、ある日いきなりBlogが消えておしまいでしょう。

(Visited 119 times, 1 visits today)
Posted in news | Tagged 10.15savvy 11.0savvy 12.0savvy 13.0savvy UI Browser | Leave a comment

Keynoteでオープン中の書類をすべてデスクトップにPDF書き出しして最初のページをJPEG画像化

Posted on 10月 15, 2022 by Takaaki Naganoya

Keynoteでオープン中の書類すべてをPDF書き出しして、各PDFの最初のページをJPEG画像に書き出すAppleScriptです。書き出し先はデスクトップフォルダです。Keynote v12.1+macOS 12.6.1で動作確認しています。

それぞれ、PDF書き出しするScriptと、PDFをJPEGに変換するAppleScriptは個別に書いて使っていたのですが、処理数が増えるといちいち複数のScriptをかわるがわる実行するのも面倒に。

そこで、PDF書き出し→JPEG変換を行うものを作ってみました。作ったみたといっても、部品はすでに存在していたので繋ぎ合わせただけです。

AppleScript名:すべてデスクトップ上にPDF出力し、最初のページをJPEG出力.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/10/14
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

property NSString : a reference to current application’s NSString
property NSFileManager : a reference to current application’s NSFileManager
property NSOrderedSame : a reference to current application’s NSOrderedSame

set outPathList to {}

tell application "Keynote"
  set allDocs to every document
  
if allDocs = {} then return
  
  
repeat with i in allDocs
    set j to contents of i
    
set dRes to exportKeynoteDocToPDF(j) of me
    
set pdfPath to (POSIX path of dRes)
    
set pdfPath to chkExistPOSIXpathAndIncrementChildNumberFull(pdfPath) of me
    
set jRes to (my jpegFromPath:(pdfPath) compressFactor:1.0)
    
set the end of outPathList to jRes
  end repeat
end tell

return outPathList

–Keynote書類からPDF書き出し
on exportKeynoteDocToPDF(targKeynoteDoc)
  
  
tell application "Keynote"
    set dCount to count every document
    
if dCount = 0 then
      –オープン中のKeynote書類がない場合はリターン
      
return false
    end if
    
    
set aPath to file of targKeynoteDoc
  end tell
  
  
set tmpPath to (path to desktop) as string
  
set curPath to (NSString’s stringWithString:(POSIX path of aPath))’s lastPathComponent()’s stringByDeletingPathExtension()’s stringByAppendingString:".pdf"
  
set outPath to (tmpPath & curPath)
  
set outPath to chkExistPOSIXpathAndIncrementChildNumberFull(outPath) of me
  
–do shell script "touch " & quoted form of POSIX path of outPath –Error 6を回避するための記述
  
  
tell application "Keynote"
    –set anOpt to {class:export options, export style:IndividualSlides, all stages:false, skipped slides:true, PDF image quality:Good}
    
–set anOpt to {class:export options, export style:IndividualSlides, all stages:false, skipped slides:true, PDF image quality:Better}
    
set anOpt to {class:export options, export style:IndividualSlides, all stages:false, skipped slides:true, PDF image quality:Best}
    
export targKeynoteDoc to POSIX file outPath as PDF with properties anOpt
  end tell
  
  
return ((POSIX file outPath) as alias)
end exportKeynoteDocToPDF

on jpegFromPath:imagePath compressFactor:compFactor — 0.0 = max compression, 1.0 = none
  — build destination path
  
set pathNSString to current application’s NSString’s stringWithString:imagePath
  
set destPath to pathNSString’s stringByDeletingPathExtension()’s stringByAppendingPathExtension:"jpg"
  
  
— load the file as an NSImage
  
set theImage to current application’s NSImage’s alloc()’s initWithContentsOfFile:imagePath
  
if theImage = missing value then return false
  
  
set theData to theImage’s TIFFRepresentation()
  
set newRep to current application’s NSBitmapImageRep’s imageRepWithData:theData
  
set theData to (newRep’s representationUsingType:(current application’s NSJPEGFileType) |properties|:{NSImageCompressionFactor:compFactor, NSImageProgressive:false})
  
  
set theResult to (theData’s writeToFile:destPath atomically:true) as boolean
  
return destPath as string
end jpegFromPath:compressFactor:

–POSIX path stringを与えると、ファイル名の重複を検出して、ファイル名の名称回避を行って、ファイル名のみを返す
on chkExistPOSIXpathAndIncrementChildNumberFull(a)
  set aa to POSIX path of a
  
set aStr to NSString’s stringWithString:aa
  
set bStr to aStr’s lastPathComponent()
  
  
set cStr to (bStr’s pathExtension()) as string
  
set dStr to (bStr’s stringByDeletingPathExtension()) as string
  
set eStr to (aStr’s stringByDeletingLastPathComponent()) as string
  
  
set aManager to NSFileManager’s defaultManager()
  
set aRes to (aManager’s fileExistsAtPath:aStr) as boolean
  
if aRes = false then return aa
  
  
set hitF to false
  
repeat with i from 1 to 65535
    
    
set tmpPath to (eStr & "/" & dStr & "_" & (i as string) & "." & cStr)
    
set tmpStr to (NSString’s stringWithString:tmpPath)
    
set aRes to (aManager’s fileExistsAtPath:tmpStr) as boolean
    
set bRes to ((tmpStr’s caseInsensitiveCompare:eStr) is not equal to (NSOrderedSame)) as boolean
    
    
if {aRes, bRes} = {false, true} then
      set hitF to true
      
exit repeat
    end if
    
  end repeat
  
  
if hitF = false then return false
  
  
–ファイルパス(フルパス)を返す
  
return (tmpStr as string)
end chkExistPOSIXpathAndIncrementChildNumberFull

★Click Here to Open This Script 

(Visited 33 times, 1 visits today)
Posted in Image PDF | Tagged 12.0savvy Keynote | Leave a comment

macOS 12.6.1、組み込みAppleScript実行環境の「script objectで分離したハンドラが呼べない」問題が解消?

Posted on 10月 12, 2022 by Takaaki Naganoya

macOS 12.6.1がアップデートして12.6.1になるというわけのわからないバージョン番号の採番ルールが展開されている今日このごろ。

macOS 12の初期において、Shortcuts.appやCotEditor内部のAppleScript実行環境において、script objectで論理分割した中にあるハンドラを呼べない という問題が確認されました。ただし、macOS 12.6.1で気づいたということであって、もう少し前のバージョンでこの変更が加わっていた可能性もあります。

ハンドラ呼び出しの範囲がscript objectを超えられないというわけで、CotEditor PowerPackの作成時に大幅にScriptを書き換える必要があって手間がかかった記憶があります。

AppleScript基礎テクニック集25巻にて「CotEditorのメニューScriptとShortcuts.appでは対策が必要」と書こうとして、念のために実際にmacOS 12.6.1の上でCotEditor v4.3.6で確認したところ、動きました。Shortcuts.appでも同様にscript object内部のハンドラを外部から呼び出せるようになっていました。

# 慌てて、書籍の方を書き換えました

各プログラム側で何かそんなマイナーな問題への対策を行ったような雰囲気はなかったので、OS側の実行モジュール(osascript?)で対策を行ったような雰囲気があります。ただ、Appleがリリースノートを一切出さないので、確認のしようがありません(ものすごく不信感しかないので、リリースノートは出してほしいなー。まさか、詳細なリリースノートを出さないことで、クラッカーへの情報流出を防止できている、とか現状を肯定的に捉えているのだろうか)。

(Visited 45 times, 1 visits today)
Posted in Bug | Tagged 12.0savvy CotEditor Shortcuts Shortcuts Events | Leave a comment

Post navigation

  • Older posts

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

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • UI Browserがgithub上でソース公開され、オープンソースに
  • Safariで表示中のYouTubeムービーのサムネイル画像を取得
  • 人類史上初、魔導書の観点から書かれたAppleScript入門書「7つの宝珠」シリーズ開始?!
  • macOS 12.5(21G72)がリリースされた!
  • macOS 13 TTS Voice環境に変更
  • 2022年に書いた価値あるAppleScript
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • Pages v12に謎のバグ。書類上に11枚しか画像を配置できない→解決
  • Xcode 14.2でAppleScript App Templateを復活させる
  • Dockに登録されている項目の情報を取得する
  • macOS 13 beta 3
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • 新発売:AppleScript基礎テクニック集(11)AppleScriptアプレットとドロップレット
  • macOS 12.5RC(21G69)、一定以上の長さのapplescript:// URL…
  • OpenAIで文章のベクトル化(Embedding)
  • macOS 12.5.1、11.6.8でFinderのselectionでスクリーンショット画像をopenできない問題

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (276) 12.0savvy (178) 13.0savvy (38) CotEditor (60) Finder (47) iTunes (19) Keynote (98) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (41) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (117) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (56) Pages (37) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) WKUserScriptInjectionTimeAtDocumentEnd (18) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • Clipboard
  • Code Sign
  • Color
  • Custom Class
  • dialog
  • drive
  • 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
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • PDF
  • Peripheral
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • 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)
  • 未分類

アーカイブ

  • 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