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

カテゴリー: list

macOS 13でNSNotFoundバグふたたび

Posted on 12月 1, 2022 by Takaaki Naganoya

また、Appleがやらかしてくれたようです。あの会社はNSNotFoundの定義値を何回間違えたら気が済むんでしょうか。これで通算4回目ぐらいです。macOS 10.12で発生し10.13.1で修正された定義値のミスをまたやったわけで、失敗がまったく生かされていない。大したものです。

今回のバグは、文字列の検索処理を行っているときに発見しました。指定文字列から対象文字列の登場位置と長さをリストで返す処理を行っていたところ、NSRangeからlocationを取得したときに、これ以上見つからない場所まで来たときにNSNotFoundを返すことを期待されるわけですが、そこに前回(macOS 10.12…10.13)と同様のおかしな値を返してきました。

この(↓)AppleScriptをmacOS 13上で実行すると、エラーになります。

追記:macOS 13.1でもエラーになります。

AppleScript名:テキストのキーワード検索(結果をNSRangeのlistで返す).scptd
— Created 2017-08-09 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
–http://piyocast.com/as/archives/4771

property NSString : a reference to current application’s NSString
property NSMutableArray : a reference to current application’s NSMutableArray
property NSLiteralSearch : a reference to current application’s NSLiteralSearch

set aStr to "ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
"

set aRes to searchWordRanges(aStr, "ATGC") of me as list
–>  {​​​​​{​​​​​​​location:0, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:10, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:20, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:30, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:40, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:50, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:60, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:70, ​​​​​​​length:4​​​​​}​​​}

on searchWordRanges(aTargText as string, aSearchStr as string)
  set aStr to NSString’s stringWithString:aTargText
  
set bStr to NSString’s stringWithString:aSearchStr
  
  
set hitArray to NSMutableArray’s alloc()’s init()
  
set cNum to (aStr’s |length|()) as integer
  
  
set aRange to current application’s NSMakeRange(0, cNum)
  
  
repeat
    set detectedRange to aStr’s rangeOfString:bStr options:(NSLiteralSearch) range:aRange
    
set aLoc to detectedRange’s location
    
log aLoc
    
if (detectedRange’s location) is equal to (current application’s NSNotFound) then exit repeat
    
    
hitArray’s addObject:detectedRange
    
    
set aNum to (detectedRange’s location) as number
    
set bNum to (detectedRange’s |length|) as number
    
    
set aRange to current application’s NSMakeRange(aNum + bNum, cNum – (aNum + bNum))
  end repeat
  
  
return hitArray
end searchWordRanges

★Click Here to Open This Script 

症状も前回とまったく同じなので、対処も前回と同じです。Appleは定期的にNSNotFoundの定義値を間違えるトンでもない会社なので(計測された事実)、NSNotFoundまわりはAppleがバグをやらかすことを前提に書いておくべきなんでしょう。

AppleScript名:テキストのキーワード検索(結果をNSRangeのlistで返す)v2.scptd
— Created 2017-08-09 by Takaaki Naganoya
— Modified 2022-12-01 by Takaaki Naganoya
— 2022 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property NSString : a reference to current application’s NSString
property NSMutableArray : a reference to current application’s NSMutableArray
property NSLiteralSearch : a reference to current application’s NSLiteralSearch

set aStr to "ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
ATGC ACGT ATGC AGTC
"

set aRes to searchWordRanges(aStr, "ATGC") of me as list
–>  {​​​​​{​​​​​​​location:0, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:10, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:20, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:30, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:40, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:50, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:60, ​​​​​​​length:4​​​​​}, ​​​​​{​​​​​​​location:70, ​​​​​​​length:4​​​​​}​​​}
–> {{location:0, |length|:4}, {location:10, |length|:4}, {location:20, |length|:4}, {location:30, |length|:4}, {location:40, |length|:4}, {location:50, |length|:4}, {location:60, |length|:4}, {location:70, |length|:4}}

on searchWordRanges(aTargText as string, aSearchStr as string)
  set aStr to NSString’s stringWithString:aTargText
  
set bStr to NSString’s stringWithString:aSearchStr
  
  
set hitArray to NSMutableArray’s alloc()’s init()
  
set cNum to (aStr’s |length|()) as integer
  
  
set aRange to current application’s NSMakeRange(0, cNum)
  
  
repeat
    set detectedRange to aStr’s rangeOfString:bStr options:(NSLiteralSearch) range:aRange
    
set aLoc to detectedRange’s location
    
    
–macOS 13でAppleが新たに作ったバグを回避
    
if (aLoc > 9.999999999E+9) or (aLoc = current application’s NSNotFound) then exit repeat
    
    
hitArray’s addObject:detectedRange
    
    
set aNum to (detectedRange’s location) as number
    
set bNum to (detectedRange’s |length|) as number
    
    
set aRange to current application’s NSMakeRange(aNum + bNum, cNum – (aNum + bNum))
  end repeat
  
  
return hitArray
end searchWordRanges

★Click Here to Open This Script 

(Visited 52 times, 1 visits today)
Posted in Bug list Text | Tagged 13.0savvy NSLiteralSearch NSMakeRange NSMutableArray NSNotFound NSRange NSString | Leave a comment

Common Elements Libをv1.3aにアップデート

Posted on 7月 12, 2022 by Takaaki Naganoya

対象のキーワードの構成情報を分解して、2つのキーワードの共通要素をリストアップする「マッキー演算」を行うライブラリ「Common Elements Lib」をアップデートしました。

–> Common Elements Libをダウンロード(v1.3a)

マッキー演算とは、「槇原敬之」と「SMAP」の共通項を求め、結果に「世界に一つだけの花」をリストアップする処理です(ほかにも出てきますが)。

–> {“第58回NHK紅白歌合戦”, “木村拓哉”, “東京都”, “ニッポン放送”, “テレビ朝日”, “ミリオンセラー”, “大阪城ホール”, “インターネットアーカイブ”, “社長”, “ミュージックステーション”, “ケンタッキーフライドチキン”, “スポーツニッポン”, “日刊スポーツ”, “第42回NHK紅白歌合戦”, “リクルートホールディングス”, “エフエム東京”, “日本ゴールドディスク大賞”, “フジテレビジョン”, “J-POP”, “小倉博和”, “世界に一つだけの花”, “We are SMAP!”, “日本”, “日本武道館”, “ISBN”}

WikipediaのMedia APIを用いて問い合わせを行って計算を行います。そのため、(Wikipedia上における当該項目の記事内容の変化によって)実行時期によって演算結果に差が出ます。

アップデート理由は、前バージョンではインターネット接続確認を「http://www.google.com」に対して行っていたところに、このドメインに対してhttp経由でのアクセスが行えないようになったので、エラーを起こすようになりました。

このドメインにhttps経由でアクセスするよう変更しました。

(Visited 29 times, 1 visits today)
Posted in Internet Library list PRODUCTS REST API | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

Keynoteの表で選択中のセルの文字列長さを一覧表で表示

Posted on 7月 4, 2022 by Takaaki Naganoya

Keynoteの最前面の書類で表示中のスライド中の表で、選択中の各セルの内容の文字列の長さを表インタフェースで一覧表示するAppleScriptです。

こんなKeynote書類上の表があったとして、その選択中の各セルに入っている文字列の長さを、AppleScriptライブラリ「display table by list」を用いて一覧表示します。実行には同ライブラリのインストールが必要です。

実行の前提として、Keynoteで書類をオープンしてあり、書類上の表の集計対象のセルを選択しておくことが必要です。

文字列長と元の文字列を一覧表示します。

AppleScript名:Keynoteの表で選択中のセルの文字列長さを一覧表で表示.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/07/04
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.5" — El Capitan (10.11) or later
use framework "Foundation"
use scripting additions
use easyTable : script "display table by list"

tell application "Keynote"
  tell front document
    tell current slide
      try
        set theTable to first table whose class of selection range is range
      on error
        display notification "Numbers: There is no selection"
        
return
      end try
      
      
tell theTable
        set aRes to value of cells of selection range
      end tell
    end tell
  end tell
end tell

set fLabels to {"文字列長", "文字列"}

set newList to {}
repeat with i in aRes
  set j to contents of i
  
if j is not equal to missing value then
    set aLen to length of j
    
set the end of newList to {aLen, j}
  end if
end repeat

tell current application
  set aRes to (display table by list newList main message "テキストの文字列長" sub message "Keynoteの表で選択中のテキストの各セルの文字列長" size {800, 400} labels fLabels icon "")
end tell

★Click Here to Open This Script 

(Visited 43 times, 2 visits today)
Posted in list Text | Tagged 10.15savvy 11.0savvy 12.0savvy Keynote | 1 Comment

1D Listを2Dに評価してアイテム内の相違点を検出

Posted on 6月 28, 2022 by Takaaki Naganoya

1次元リスト(配列)を幅を指定しつつ2次元リストとして評価し、1番左側のセルとの変化を横方向にサーチして検出するAppleScriptです。

もともと、macOS標準搭載の「辞書.app」に収録される各辞書データの名称が、各OSバージョンでどのように変化しているかを表計算ソフトNumbers上でチェックしていました。辞書.appの辞書をCocoa Frameworkを通じて呼び出し、さまざまな便利な処理を行っているため、辞書名称が変わると日常的に利用しているAppleScriptに影響が出てしまいます。その変化を検出するために、辞書名の変化を知っておこうというチェック作業が発生しています。

辞書.appの収録辞書名称は、意図したものか意図していないものか不明ですが、OSバージョンごとに微妙に変化することが知られています。そうした名称細部の変化を実際にチェックするのに、専用のScriptを使っていました(過去形)。

ただし、NumbersのデータをAppleScriptから取得すると、2D Listではなく1D Listとして返ってきます。そのさいに、BridgePlusの機能を用いて1D→2D変換を行ったのちに、いろいろ処理を行ってきました。

リストの1D→2D変換処理なんて、使っている場所が多すぎて数えきれないぐらいですが、Script Menu上で動かすScriptでBridgePlusを呼び出せなくなっており(macOS 10.14以降)、今後Script Menuが機能強化されるとは考えにくいところです。

サードパーティのFastScriptsなどでFramework入りScriptの実行をサポートするとか、そういう進化ができてほしいところですが、それもちょっと期待できません。

結果として、BridgePlusを極力使わなくて済むように、機能の置き換えを進めるしかありません。無理な機能もありますが、1D→2D変換ぐらいなら問題ありません(そして、出現頻度がおっそろしく高いものであります)。

そして、実際にNumbers上のデータを横方向(左→右、冒頭から末尾へ)に走査して変更を検出する処理を書いてみました。

処理に柔軟性が欲しかったので、追加でフラグ(reNewF)を用意しました。

これがfalseの場合には、横方向に変更を走査し、変化を検出した場合には評価を打ち切ります。trueの場合には、変化を検出した場合でも変化の検出を続行します。

AppleScript名:1D Listを2D的に評価してアイテム内の相違点を検出.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/06/28
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4" — Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set aList to {1, 1, 1, 2, 3, 3, 3, 3, 3, 4, 3, 5}
set diffRes to getListDifference2D(aList, 3, true) of me
–> {{xAddrs:{2}, yAddr:2}, {xAddrs:{2}, yAddr:4}}–reNewF=falseで評価
–> {{xAddrs:{2}, yAddr:2}, {xAddrs:{2, 3}, yAddr:4}}—reNewF=true で評価

–1D Listを、2D Listとして評価しつつ、{cell1, cell2, cell3}のcell 1とcell2, cell3が違っていないか評価して返す
on getListDifference2D(dList as list, aWidth as integer, reNewF as boolean)
  script tdSpd
    property dList : {}
  end script
  
  
copy dList to (dList of tdSpd)
  
  
set diffList to {}
  
set diffAdrList to {}
  
  
set yOffsetCount to 1
  
  
set aCountMax to ((length of dList) div aWidth)
  
  
repeat with aC from 1 to (length of dList) by aWidth
    set tmpList to items aC thru (aC + aWidth – 1) of (dList of tdSpd)
    
    
set i1 to first item of tmpList
    
set i2 to rest of tmpList
    
    
set xOffsetCount to 2
    
set xDiffList to {}
    
    
repeat with ii in i2
      set jj to contents of ii
      
      
if i1 is not equal to jj then
        set the end of diffList to {i1, jj}
        
set the end of xDiffList to xOffsetCount
        
        
if reNewF = true then
          copy jj to i1
        else
          exit repeat
        end if
      end if
      
      
set xOffsetCount to xOffsetCount + 1
      
    end repeat
    
    
if xDiffList is not equal to {} then
      set the end of diffAdrList to {xAddrs:xDiffList, yAddr:yOffsetCount}
    end if
    
    
set yOffsetCount to yOffsetCount + 1
  end repeat
  
  
return diffAdrList
end getListDifference2D

★Click Here to Open This Script 

(Visited 31 times, 1 visits today)
Posted in list | Tagged 10.14savvy 10.15savvy 11.0savvy 12.0savvy Numbers | Leave a comment

Keynote上でテキストアイテムとn重のシェープの重なりを検出 v2

Posted on 6月 25, 2022 by Takaaki Naganoya

Keynoteでオープン中の最前面の書類の現在のスライド(ページ)の上で3重のshapeオブジェクトを下に敷いているテキストアイテムを検出し、文字色を変更するAppleScriptです。

macOS 12.5beta+Keynote v12.1の組み合わせで作成・チェックしてみましたが、Keynote v12.xの固有の機能などは使っていないので、もっと古い環境でも動くはずです。

–> Watch Demo Movie


▲処理前


▲処理後 右側のテキストの色まで変わってしまっているのは意図しなかった処理(わかってたけど)

Keynote書類上でshapeオブジェクトを重ねて何かを表現することはよくありますが、重ねた場所の上に置いてある文字色だけ変更したい場合が往々にしてあります。

さっさと動かすことだけ考えて、ありものの「オブジェクトの重ね合わせ検出」Scriptを使い回しました。そのため、本当に入れ子状態の3つのオブジェクトを検出しているわけではなく、重ね合わせが3回発生しているテキストアイテムを検出しています。

もうちょっと凝った処理を行えば、本当に3階層の入れ子状態のshapeを検出できそうな気はしますが、さすがに使い捨てレベルのScriptにそんなに手間暇をかけるわけにもいかないので、現状ではこんなものでしょう。

Keynoteのselectionがまともに動くようになったので、いろいろ実践的なレベルのScriptを書けるようになりましたが、オブジェクトの重ね合わせ順なども取れたりすると、もっといろいろ書けそうです。

オブジェクトのposition、width、heightを取得する処理は、もうちょっと高速に実行できるように書けそうです(まだまだ、安全第一の処理内容)。

あとは、imageオブジェクトのpathとかイメージデータそのものを取得して、各種画像フィルタをかけてKeynote書類に書き戻せるとよさそうな気がします。

AppleScript名:テキストアイテムと1重のシェープの重なり検出 v2.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/06/25
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

set collisonNum to 1
set targPointSize to 32.0
set targColList to {0, 0, 0} –Black

set tList to {} –text items
set trList to {}

set sList to {} –shapes
set srList to {}
–set bgColList to {} –background color

set colList to choose color

tell application "Keynote"
  tell front document
    tell current slide
      
      
–text itemの情報抽出ループ
      
set allTList to every text item
      
repeat with i in allTList
        set j to contents of i
        
        
tell j
          set {xPos, yPos} to position
          
set aWidth to width
          
set aHeight to height
          
set aRect to makeRect(xPos, yPos, aWidth, aHeight) of me
        end tell
        
        
set the end of tList to j
        
set the end of trList to aRect
      end repeat
      
      
      
–shapeの情報抽出ループ
      
set allSList to every shape
      
repeat with i in allSList
        set j to contents of i
        
tell j
          set {xPos, yPos} to position
          
set aWidth to width
          
set aHeight to height
          
–set aBGCol to background color
          
set aRect to makeRect(xPos, yPos, aWidth, aHeight) of me
        end tell
        
        
set the end of sList to j
        
set the end of srList to aRect
        
set the end of bgColList to aBGCol
        
      end repeat
      
      
set atLen to length of trList
      
set arLen to length of srList
      
      
set outTlist to {}
      
      
      
–shapeと重ね合わせが発生しているtext itemの検出ループ
      
repeat with i from 1 to atLen
        set atRec to contents of item i of trList
        
set atObj to contents of item i of tList
        
set collisionC to 0
        
        
set tmpCSize to point of first character of object text of atObj
        
        
–当該text itemに対して、shapeオブジェクトとのNSRectの重ね合わせが指定数発生しているかをチェック
        
repeat with ii from 1 to arLen
          set tmpRect to contents of item ii of srList
          
set aF to detectRectanglesCollision(atRec, tmpRect) of me
          
          
–背景色(background color)のリストを確認
          
set aBG to contents of item ii of bgColList
          
          
–if {aF, aBG, tmpCSize} = {true, targColList, targPointSize} then set collisionC to collisionC + 1
          
if {aF, tmpCSize} = {true, targPointSize} then set collisionC to collisionC + 1
        end repeat
        
        
–オブジェクトのRectangleが重なり合っている「回数」で判定
        
if collisionC = collisonNum then
          set the end of outTlist to atObj
        end if
      end repeat
    end tell
  end tell
end tell

–文字色を塗り替えるループ
tell application "Keynote"
  tell front document
    tell current slide
      repeat with i in outTlist
        set j to contents of i
        
ignoring application responses
          set color of object text of j to colList
        end ignoring
      end repeat
    end tell
  end tell
end tell

on makeRect(xPos, yPos, aWidth, aHeight)
  return current application’s NSMakeRect(xPos, yPos, aWidth, aHeight)
end makeRect

–NSRect同士の衝突判定
on detectRectanglesCollision(aRect, bRect)
  set a1Res to (current application’s NSIntersectionRect(aRect, bRect)) as {record, list}
  
set tmpClass to class of a1Res
  
  
if tmpClass = record then
    –macOS 10.10, 10.11, 10.12
    
return not (a1Res = {origin:{x:0.0, y:0.0}, |size|:{width:0.0, height:0.0}})
  else if tmpClass = list then
    –macOS 10.13 or later
    
return not (a1Res = {{0.0, 0.0}, {0.0, 0.0}})
  end if
end detectRectanglesCollision

–1から任意の数までのアイテムで、2個ずつの組み合わせのすべての順列組み合わせパターンを計算して返す
–ただし、1×1とか2×2などの同一アイテム同士の掛け合わせを除去するものとする
on retPairPermutationsWithoutSelfCollision(aMax)
  set aList to {}
  
  
repeat with x from 1 to aMax
    repeat with xx from 1 to aMax
      if x is not equal to xx then
        
        
set tmpItem to {x, xx}
        
set a2List to sort1DNumList(tmpItem, true) of me
        
        
if {a2List} is not in aList then
          set the end of aList to a2List
        end if
      end if
      
    end repeat
  end repeat
  
  
return aList
end retPairPermutationsWithoutSelfCollision

–1D List(数値)をsort / ascOrderがtrueだと昇順ソート、falseだと降順ソート
on sort1DNumList(theList as list, aBool as boolean)
  tell current application’s NSSet to set theSet to setWithArray_(theList)
  
tell current application’s NSSortDescriptor to set theDescriptor to sortDescriptorWithKey_ascending_(missing value, aBool)
  
set sortedList to theSet’s sortedArrayUsingDescriptors:{theDescriptor}
  
return (sortedList) as list
end sort1DNumList

★Click Here to Open This Script 

(Visited 43 times, 1 visits today)
Posted in bounds list Object control | Tagged 10.15savvy 11.0savvy 12.0savvy Keynote | Leave a comment

相対パスを計算で求める

Posted on 6月 14, 2022 by Takaaki Naganoya

指定のPOSIX pathを元に相対パスを計算するAppleScriptです。

Unix shellであれば、相対パスについては「../../../」などと表現できるわけですが、シェルを介さずに計算する方法が見つからなかったので、必要に迫られて作っておきました。

AppleScript名:上位パスを相対的に求める.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/06/14
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

set aFile to "/Users/me/Documents/1/2/3"

set aNum to 1
set bFile to getUpperDir(aFile, aNum) of me

–> "/Users/me/Documents/1/2"

set aNum to 2
set cFile to getUpperDir(aFile, aNum) of me
–>"/Users/me/Documents/1"

set aNum to 3
set dFile to getUpperDir(aFile, aNum) of me
–> "/Users/me/Documents"

–与えられたパスから指定階層「上」のパスを求める
on getUpperDir(aPOSIXpath as string, aNum as integer)
  if aNum < 1 then return aPOSIXpath
  
set pathString to current application’s NSString’s stringWithString:aPOSIXpath
  
repeat aNum times
    set pathString to pathString’s stringByDeletingLastPathComponent()
  end repeat
  
return pathString as string
end getUpperDir

★Click Here to Open This Script 

AppleScript名:下位パスを配列で追加して求める.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/06/14
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

set aPOSIXpath to "/Users/me/Documents/" –AppleScriptのPOSIX path表現(フォルダを表現するさい、末尾に「/」)
set catDirList to {"1", "2", "3"}
set bPath to getChildPathByAppendingDirsByArray(aPOSIXpath, catDirList) of me
–> /Users/me/Documents/1/2/3

set aPOSIXpath to "/Users/me/Documents" –CocoaのPOSIX path表現(フォルダを表現する場合でも、末尾に「/」入らず)
set catDirList to {"3", "2", "1"}
set cPath to getChildPathByAppendingDirsByArray(aPOSIXpath, catDirList) of me
–> "/Users/me/Documents/3/2/1"

on getChildPathByAppendingDirsByArray(aPOSIXpath, catDirList)
  set pathString to current application’s NSString’s stringWithString:aPOSIXpath
  
set aList to (pathString’s pathComponents()) as list
  
set aList to aList & catDirList
  
  
set bPath to current application’s NSString’s pathWithComponents:aList
  
return bPath as string
end getChildPathByAppendingDirsByArray

★Click Here to Open This Script 

(Visited 44 times, 2 visits today)
Posted in File path list Text | Tagged 10.13savvy 10.14savvy 10.15savvy 11.0savvy 12.0savvy | Leave a comment

RectangleBinPackを用いて2D Bin Packを解く v2.3

Posted on 5月 31, 2022 by Takaaki Naganoya

オープンソースの「RectangleBinPack」を用いて2D Bin Packagingを解き、Keynote上の汎用オブジェクト(iWork item)を指定矩形内に詰め込むAppleScriptです。

–> Watch Demo Movie

2D Bin Packは、指定のオブジェクトを面積で評価して、ターゲットの領域に「詰め込む」(オブジェクト回転あり)という処理で、ワードクラウドであるとか、記事レイアウト時の最適化配置といった用途に用いられます。

さまざまなアルゴリズムが提唱され、コンピュータの登場初期からどえらい先人たちが攻めまくった分野であるため、ありがたく、その成果をいただいているという用途でもあります。

よく、ゲームのテクスチャ画像を1枚の画像ファイルに詰め込む際に2D Bin Packの処理を用いている例を見かけます。なんでファイルごとに分けないのかはわかりませんけれども(ファイル容量の節約???)。

–> Download Script bundle with RectangleBinPack in its bundle + sample Keynote document

# This AppleScript requires RectangleBinPack executable in its bundle. So, download the whole AppleScript bundle archive from the link above (↑)

オープン中のKeynote書類の表示中のスライド(ページ)上にある矩形オブジェクト(Shape)を指定の矩形エリア内に2D Packingします。エリアの大きさが小さすぎると正常にPackingされなかったり、false(エラー)を返したりします。

変更履歴:

v2.1: BinPackTestをIntel x64とARM binaryのそれぞれのバイナリでビルドしてバンドルに入れた(Makeを書き換えて直接Universalバイナリに仕立てられるといいのに)
v2.2: BridgePlusがなくても動くように書き換えた(ないと動かないのはいろいろ運用上問題がある)
v2.3: shapeに対してBinPackしていたのを、Keynote上の汎用オブジェクトへのアクセス予約語iWork itemでアクセスするように変更した

AppleScript名:rectBinPack v2.3_Universal.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/05/31
—
–  Copyright © 2019-2022 Piyomaru Software, All Rights Reserved
—
— 2D Bin Packing by juj https://github.com/juj/RectangleBinPack
— v2.1: BinPackTestをIntel x64とARM binaryのそれぞれのバイナリでビルドしてバンドルに入れた(Universalバイナリに仕立てられるといいのに)
— v2.2: BridgePlusを外した(ないと動かないのはいろいろ運用上問題がある)
— v2.3: shapeに対してBinPackしていたのを、Keynote上の汎用オブジェクトへのアクセス予約語iWork itemでアクセスするように変更した

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

–Packaging Target Area
set binSizeX to 600
set binSizeY to 600

set packRes to packKeynoteObjectsOnCurrentSlide(binSizeX, binSizeY) of me

on packKeynoteObjectsOnCurrentSlide(binSizeX, binSizeY)
  set {tList, a0List} to retRectsFromKeynote() of me
  
  
set aList to sortList2DDecending(a0List, {"myWidth", "myHeight", "myArea"}) of me –Sorting key is Width(main) and Area(sub) and Height(sub)
  
  
set aRes to twoDBinPacking(binSizeX, binSizeY, aList) of me
  
if aRes = false then return false
  
  
tell application "Keynote"
    tell front document
      tell current slide
        repeat with i in aRes
          set {posX, posY} to myPos of i
          
set itemIndex to myID of i
          
set aDeg to myDegree of i
          
          
–sample data {itemCounter:5, myWidth:573, myHeight:52, myArea:29796}
          
set anObjID to itemCounter of (item itemIndex of aList)
          
          
set rotation of iWork item anObjID to aDeg
          
set position of iWork item anObjID to {posX, posY}
        end repeat
      end tell
    end tell
  end tell
  
  
return true
end packKeynoteObjectsOnCurrentSlide

on twoDBinPacking(binSizeX as integer, binSizeY as integer, boxList as list)
  set aParamList to {binSizeX, binSizeY}
  
  
repeat with i in boxList
    –copy i to {tmpID, tmpX, tmpY, tmpArea}
    
— {itemCounter:iCount, myWidth:aWidth, myHeight:aHeight, myArea:anArea}
    
set tmpID to itemCounter of i
    
set tmpX to myWidth of i
    
set tmpY to myHeight of i
    
set tmpArea to myArea of i
    
    
set aParamList to aParamList & tmpX
    
set aParamList to aParamList & tmpY
  end repeat
  
  
set aParam to retDelimitedText(aParamList, " ") of me
  
–> "800 800 340 243 340 73 340 73 155 240 147 125 147 125 147 125 147 125"
  
  
–Parameters for result parsing
  
set s1Str to "Packed to (x,y)=("
  
set s2Str to ")"
  
set s3Str to ","
  
  
set cpuRes to CPU type of (system info)
  
if cpuRes begins with "ARM" then
    set exName to "arm"
  else if cpuRes begins with "Intel" then
    set exName to "x86"
  end if
  
  
set binName to "BinPackTest_" & exName
  
set aPath to POSIX path of (path to resource binName)
  
  
try
    set aRes to do shell script quoted form of aPath & " " & aParam
  on error
    return false
  end try
  
  
if aRes does not end with "Done. All rectangles packed." then return false
  
  
set aList to paragraphs of aRes
  
  
set bList to {}
  
set aCount to 1
  
repeat with i in aList
    set j to contents of i
    
if j begins with "Packing rectangle of size " and j does not contain "Failed!" then
      set xyRes to pickUpFromToStrAndParse(j, s1Str, s2Str, s3Str) of me
      
      
–RectangleBinPackがオブジェクトの回転をサポートしているため、その対処
      
if xyRes is not equal to false then
        set s11Str to "(w,h)=("
        
set s12Str to ")"
        
set s13Str to ","
        
        
set whRes to pickUpFromToStrAndParse(j, s11Str, s12Str, s13Str) of me
        
set tmpBox to item aCount of boxList
        
        
— {itemCounter:5, myWidth:573, myHeight:52, myArea:29796}
        
–copy tmpBox to {tmpID, tmpX, tmpY, tmpArea}
        
set tmpID to itemCounter of tmpBox
        
set tmpX to myWidth of tmpBox
        
set tmpY to myHeight of tmpBox
        
set tmpArea to myArea of tmpBox
        
        
if whRes = {tmpX, tmpY} then
          set aDeg to 0
        else if whRes = {tmpY, tmpX} then
          set aDeg to 90
        else
          return false
        end if
        
        
set the end of bList to {myPos:xyRes, myID:aCount, myDegree:aDeg}
      end if
      
set aCount to aCount + 1
    end if
  end repeat
  
  
return bList
end twoDBinPacking

on pickUpFromToStrAndParse(aStr as string, s1Str as string, s2Str as string, s3Str 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
  
set {x, y} to parseByDelim(cStr, s3Str) of me
  
  
return {x as integer, y as integer}
end pickUpFromToStrAndParse

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

–リストを指定デリミタでテキスト化
on retDelimitedText(aList, aNewDelim)
  set aText to ""
  
set curDelim to AppleScript’s text item delimiters
  
set AppleScript’s text item delimiters to aNewDelim
  
set aText to aList as text
  
set AppleScript’s text item delimiters to curDelim
  
return aText
end retDelimitedText

on retRectsFromKeynote()
  tell application "Keynote"
    tell front document
      tell current slide
        set tList to every iWork item
        
set bList to {}
        
set iCount to 1
        
        
repeat with i in tList
          set aWidth to width of i
          
set aHeight to height of i
          
set {xPos, yPos} to position of i
          
set anArea to aWidth * aHeight
          
          
set the end of bList to {itemCounter:iCount, myWidth:aWidth, myHeight:aHeight, myArea:anArea}
          
set iCount to iCount + 1
        end repeat
        
        
return {tList, bList}
      end tell
    end tell
  end tell
end retRectsFromKeynote

–入れ子のリストを降順ソート
on sortList2DDecending(a, keyLabelList)
  set fLen to length of keyLabelList
  
set fList to {}
  
  
repeat fLen times
    set the end of fList to false
  end repeat
  
  
return cocoaSortListAscending(a, keyLabelList, fList) of me
end sortList2DDecending

–Cocoaで入れ子のリストをソート true:昇順、false:降順
on cocoaSortListAscending(theList as list, keyLabelList as list, ascendingF as list)
  set anArray to current application’s NSMutableArray’s arrayWithArray:(theList)
  
  
set sortDesc to {}
  
set dLen to length of keyLabelList
  
repeat with i from 1 to dLen
    set tmpKeyLabel to contents of item i of keyLabelList
    
set tmpSortF to contents of item i of ascendingF
    
set theDescriptor to (current application’s NSSortDescriptor’s sortDescriptorWithKey:(tmpKeyLabel) ascending:(tmpSortF))
    
set the end of sortDesc to theDescriptor
  end repeat
  
  
set sortedList to anArray’s sortedArrayUsingDescriptors:(sortDesc)
  
  
return sortedList as list
end cocoaSortListAscending

★Click Here to Open This Script 

(Visited 32 times, 1 visits today)
Posted in 2D Bin Packing list Sort | Tagged 11.0savvy 12.0savvy Keynote | 1 Comment

Keynoteで選択中のスライドのすべての表のセル内文字色を黒にする

Posted on 5月 27, 2022 by Takaaki Naganoya

Keynote v12.0以降で、最前面の書類で選択中のスライド(複数可)にある表のすべての文字色を「黒」に変更するAppleScriptです。

–> Watch Demo Movie

Keynote v12.0で「selection」がまともに機能するようになったので、Keynote用Scriptの実用性がたいへんに高まっています。

# ファイル保存できないとかいうバグが一刻も早く治ることを希望しています。とくに、Pages!

もともと、複数ページにわたって掲載している「表」の中に赤字でマークした箇所があって、そのマークの意図とは別の赤字を入れたかったので、いったんすべて書式をリセットしたかったので書いたものです。

もうちょっと長いScriptを書かなければならないかと思っていたのですが、ことのほかシンプルに書けました。
もっとシンプルに書けるか(everyを使ってスライドごと指定するとか)も試してみたのですが、どうやらこのあたりが限界のようです。

Keynoteのselectionを活かしたScriptでいまいちばん活躍しているのは、Keynoteのテキストアイテム(text item)から内容を取得して、メモリ上でAppleScriptとしてコンパイルし、構文色分けを反映させたスタイル付きテキストを取得して、テキストアイテムに書式を反映させるものです。実に、Keynote上にテキストで書いておいたAppleScriptのリストを構文色分けを反映させた掲載リストに変換できるので便利です。

AppleScript名:Keynoteで選択中のスライドのすべての表のセル内文字色を黒にする.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/05/27
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

tell application "Keynote"
  set aVer to version
  
  
considering numeric strings
    if aVer < 12.0 then return –Keynote v12.0より以前のバージョンでは実行できない
  end considering
  
  
tell front document
    set aaSel to selection
    
set selClass to class of contents of first item of aaSel
    
if selClass is not equal to slide then return –選択中のオブジェクトがslide(ページ)でなければ処理終了
    
    
repeat with i in aaSel
      set j to contents of i
      
      
tell j
        –現在のスライド上のすべての表のすべてのセルの文字色を黒 {0, 0, 0}に
        
set text color of every cell of every table to {0, 0, 0}
      end tell
      
    end repeat
    
  end tell
  
end tell

★Click Here to Open This Script 

(Visited 40 times, 1 visits today)
Posted in list Object control | Tagged 10.15savvy 11.0savvy 12.0savvy Keynote | Leave a comment

Keynoteで選択中のGroup内オブジェクトを座標でソートし、テキスト抜き出し

Posted on 5月 15, 2022 by Takaaki Naganoya

Keynote v12.0以降でオープン中の最前面の書類の、表示中のスライド(ページ)上で選択中のグループから、その内部に収められているオブジェクトからテキストを取り出し、リスト(配列)にまとめるAppleScriptです。


▲書類上のオブジェクト(グループ)を選択した状態


▲1冊分のデータがグループにまとめられており、グループ内にオブジェクトを格納

いったんデータを組み上げた「書類」からデータを抜き出すのは、AppleScriptの重要な仕事です。各データ内のフィールドについて座標情報から自動判別するようにしていますが、座標値が想定どおりになっていない場合もあるため、これでもまだ不十分なので、相対的な位置関係(左上、右上、下 などといった)を定義してデータを取り出すようにするとよいでしょう。

……そこまで高度なものを作らなくても、文字列の長さに着目してソートしたら瞬殺でした。

AppleScript名:選択中のGroup内オブジェクトを座標でソートし、テキスト抜き出し.scpt
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property NSFont : a reference to current application’s NSFont
property NSColor : a reference to current application’s NSColor
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

script spd
  property allList : {}
  
property aaSel : {}
end script

set (allList of spd) to {}

tell application "Keynote"
  set aVer to version
  
if aVer < "12.0" then return
  
  
set acceptClass to {text item, shape}
  
  
tell front document
    set (aaSel of spd) to selection –need Keynote v12.0 or later
    
    
repeat with i in (aaSel of spd)
      set j to contents of i
      
set aClass to class of j
      
      
if aClass = group then
        tell j
          set gItemList to every iWork item
        end tell
        
        
set posList to {}
        
set aCount to 1
        
        
repeat with ii in gItemList
          set jj to contents of ii
          
set bClass to class of jj
          
          
if bClass is in acceptClass then
            tell jj
              set {posX, posY} to position
              
              
try
                set tmpStr to object text as string
              on error
                set tmpStr to ""
              end try
            end tell
            
            
set the end of posList to {positionX:posX, positionY:posY, objID:aCount, myStr:tmpStr}
          end if
          
          
set aCount to aCount + 1
        end repeat
        
        
–座標データをもとにソート
        
set sortedList to sortRecListByLabel(posList, {"positionY", "positionX"}, {true, true}) of me
        
        
–1グループ分のテキストを組み立てる
        
set tmpList to {}
        
repeat with ii in sortedList
          set jj to contents of ii
          
set aStr to myStr of jj
          
set the end of tmpList to aStr
        end repeat
        
set the end of (allList of spd) to tmpList
      end if
    end repeat
  end tell
end tell

return (allList of spd)
–> {{"変数名", "❺", "意外と苦労している人が多い、変数やプロパティ名の命名ルール。とくに、予約語と衝突しない名前について"}, {"条件分岐", "❼", "条件分岐はプログラムに必須。自転車でいえば、カーブで曲がれないとか、水たまりを避けられないぐらい困ります。"}, {"用語辞書", "❹", "読めないと書けない、でも、あの人もこの人も読めない用語辞書。自由自在に読めれば、自由自在に書ける!"}, {"ループ処理", "➓", "プログラムをシンプルに書くための一番大事な構文。書き方によって速度が違ったり、高度な処理を簡潔に書ける!"}, {"アプレット", "⓫", "AppleScriptをアプリケーションとして書き出す、簡易アプリケーション「アプレット」の最新動向!"}, {"間接指定", "❶", "対象としたデータだけでなく、幅広いデータに対応できるよう、プログラムに柔軟性を与える間接指定"}, {"ダイアログ表示", "❾", "簡単に行えるメッセージ表示手段。外部ライブラリの利用でさらなる高機能ダイアログを紹介。"}, {"環境整備", "❽", "macOSに標準で入っているツールを呼び出しやすくしたり設定したりする程度。全体像を掴んでレッツ環境整備。"}, {"フィルタ参照", "❻", "AppleScript独特の概念で、「膨大なデータから正規表現で絞り込む」などの他の処理系と異なる、基礎にして奥義"}, {"tellブロック", "❷", "AppleScriptの7割以上を占める、tellブロックの記述や整理方法を楽に書く秘訣のかずかず"}, {"❸", "ファイルパス", "まさに「基礎」中の「基礎」。「できて当たり前」といえるパス操作。知っているだけで差がつく基礎"}}

–リストに入れたレコードを、指定の属性ラベルの値でソート
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) as list
end sortRecListByLabel

★Click Here to Open This Script 

(Visited 38 times, 1 visits today)
Posted in list Sort | Tagged 12.0savvy Keynote | Leave a comment

Keynoteで選択中のtext itemとshapeをもとにtext itemを敷き詰める

Posted on 4月 15, 2022 by Takaaki Naganoya

Keynote v12で正常化した「selection」を用いて、選択中のshapeオブジェクトの範囲に、選択中のtext itemを指定数敷き詰めるAppleScriptです。

–> Watch Demo Movie

Keynote書類上に、敷き詰める領域を示すshapeオブジェクトを1つ、敷き詰める内容を示すtext itemオブジェクトを1つ配置し、これら2つを選択して本Scriptを実行。

選択状態で実行。

指定の最小文字サイズから最大文字サイズ(Keynote書類上で選択したtext item中の文字サイズ)までの間で乱数選択しつつ、指定個数を指定エリア中に作成します。

AppleScript名:選択中のtext itemとshapeをもとにtext itemを敷き詰める.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/04/15
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

property textItem : missing value
property shapeItem : missing value

property objMax : 200 –生成するオブジェクト(text item)の個数
property fontSizeMin : 12 –生成するオブジェクト内のobject textのフォントサイズ(これ以下のサイズは生成しない)

tell application "Keynote"
  set aVer to (version as real)
  
if aVer < 12 then return
  
  
tell front document
    –書類上で選択中のオブジェクトを種別に抽出する
    
set aaSel to selection
    
if length of aaSel is not equal to 2 then error "You have to select one text item and one shape."
    
    
repeat with i in aaSel
      set j to contents of i
      
set tmpClass to class of j
      
      
if tmpClass = text item and textItem = missing value then
        set textItem to j
      else if tmpClass = shape and shapeItem = missing value then
        set shapeItem to j
      end if
    end repeat
    
    
if {textItem, shapeItem} contains missing value then error "Selected objects are not suitable"
    
    
    
–選択されたshapeオブジェクトから情報を取得
    
set aPos to (position of shapeItem)
    
set minX to item 1 of aPos
    
set maxX to minX + (width of shapeItem)
    
set minY to item 2 of aPos
    
set maxY to minY + (height of shapeItem)
    
    
–選択されたtext itemオブジェクトから情報を取得
    
set maxFSize to size of object text of textItem
    
set oText to object text of textItem
    
set tWidth to width of textItem
    
set tHeight to height of textItem
    
    
    
–shapeオブジェクトで指定された領域に、text itemを生成
    
repeat objMax times
      –座標を乱数で指定
      
set randomX to random number from minX to (maxX – tWidth)
      
set randomY to random number from minY to (maxY – tHeight)
      
–文字サイズを乱数で指定
      
set randomCSize to random number from fontSizeMin to maxFSize
      
      
tell current slide
        set tmpT to make new text item with properties {object text:oText, position:{randomX, randomY}, width:tWidth, height:tHeight} at the end
        
ignoring application responses
          set size of every character of object text of tmpT to randomCSize
        end ignoring
      end tell
      
    end repeat
  end tell
end tell

★Click Here to Open This Script 

(Visited 35 times, 1 visits today)
Posted in list | Tagged 10.15savvy 11.0savvy 12.0savvy Keynote | Leave a comment

Keynoteで選択中のオブジェクトを取得して座標でソート

Posted on 4月 10, 2022 by Takaaki Naganoya

Keynote 12.0でまともになった「selection」を使って、選択状態にあるKeynote書類上のオブジェクト(text item)をX座標、Y座標でソートするAppleScriptです。

--> {{objID:2, positionY:219, myCon:"①①①①①", positionX:184}, {objID:4, positionY:492, myCon:"❷❷❷❷❷", positionX:184}, {objID:1, positionY:219, myCon:"③③③③③", positionX:1047}, {objID:3, positionY:492, myCon:"❹❹❹❹❹", positionX:1047}}

選択したtext itemを座標で並べ替え、内容を個別に評価してファイル書き出しするAppleScriptを別途用意して書籍作成用のツールとして、使っています。

書籍の作成作業用に作ったので、アホみたいに高機能です。text itemの内容をAppleScriptとして構文確認して、AppleScriptのオブジェクトを生成し、中間言語コードに解釈ずみの.scptファイルとして書き出しています(書籍のサンプルScript生成用)。こういうツールを作ってすぐに実戦投入できるのも、Keynoteのselectionがまともになったおかげです。

–> Watch Demo Movie

AppleScript名:選択中のオブジェクトを座標をもとにソート.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/04/09
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

tell application "Keynote"
  tell front document
    set aaSel to selection
    
set posList to {}
    
set aCount to 1
    
    
repeat with i in aaSel
      set j to contents of i
      
set mySource to object text of j
      
      
tell j
        set {posX, posY} to position
      end tell
      
      
set the end of posList to {positionX:posX, positionY:posY, objID:aCount, myCon:mySource}
      
      
set aCount to aCount + 1
    end repeat
    
  end tell
end tell

set zList to sortRecListByLabel(posList, {"positionX", "positionY"}, {true, true}) of me

–リストに入れたレコードを、指定の属性ラベルの値でソート
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) as list
end sortRecListByLabel

★Click Here to Open This Script 

(Visited 38 times, 1 visits today)
Posted in list Sort | Tagged 11.0savvy 12.0savvy Keynote | Leave a comment

Keynoteの最前面の書類の現在のスライド上の表オブジェクトの重なり合い(2つ以上対応)を検出 v3

Posted on 4月 5, 2022 by Takaaki Naganoya

Keynote書類の現在のスライド(ページ)上に存在する表オブジェクトの重なり合いを検出するAppleScriptです。

前バージョンでは、複数の表オブジェクトが配置されていると、表オブジェクトの位置情報と大きさから生成したNSRect同士の重なりチェックを行なった際に、同じ表同士の重なりチェックも行なっていたので、

複数の表が存在していると、もれなく「重なっている」という警告が出てくるものでした。

本バージョンでは、同じ表同士を重なりチェックしないようにとか、1×3と3×1という「同じオブジェクト同士の重なりチェックを2度行っている」ようなものを排除しています。

今度の順列組み合わせパターン生成ルーチン「retPairPermutationsWithoutSelfCollision」では、これらのパターンを除去しています。

{{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 3}, {2, 4}, {2, 5}, {3, 4}, {3, 5}, {4, 5}}

↑余計な組み合わせパターンは生成されなくなりました。

実際に本Scriptを用いて(複数ページ対応板)、121ページ分の表の重なり合わせチェックを行なってみたところ、M1 Mac miniで3.4秒程度です。

–> Watch Demo Movie


▲重なり合わせ判定:なし


▲重なり合わせ判定:あり


▲重なり合わせ判定:なし


▲重なり合わせ判定:あり(400%拡大表示)


▲重なり合わせ判定:あり(75%拡大表示)

本Scriptの完全版を「AppleScript基礎テクニック集(1)〜間接指定」に収録しています。

AppleScript名:現在のスライド上の表オブジェクトの重なり合い(2つ以上対応)を検出 v3.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/04/03
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

tell application "Keynote"
  tell front document
    set docHeight to height
    
    
tell current slide
      set tList to every table
      
      
if length of tList < 2 then return false –複数の「表」がなかったら衝突は発生していない
      
      
–表の座標とサイズによりNSRectangleを作成する
      
set bList to {}
      
      
repeat with i in tList
        set j to contents of i
        
        
tell j
          set {xPos, yPos} to position
          
set aWidth to width
          
set aHeight to height
          
          
set aRect to makeRect(xPos, yPos, aWidth, aHeight) of me
        end tell
        
        
set the end of bList to aRect
      end repeat
      
      
–作成したNSRectangleの順列組み合わせペア・パターンを作成して、NSRectangle同士の衝突判定を順次行う
      
set aLen to length of bList
      
set permuList to retPairPermutationsWithoutSelfCollision(aLen) of me
      
set corruptList to {}
      
      
repeat with i in permuList
        copy i to {i1, i2}
        
set rectRes to detectRectanglesCollision(item i1 of bList, item i2 of bList) of me
        
if rectRes = true then return true –表同士の衝突が発生している
      end repeat
      
      
return false –表同士の衝突は発生していない
    end tell
  end tell
end tell

on makeRect(xPos, yPos, aWidth, aHeight)
  return current application’s NSMakeRect(xPos, yPos, aWidth, aHeight)
end makeRect

–NSRect同士の衝突判定
on detectRectanglesCollision(aRect, bRect)
  set a1Res to (current application’s NSIntersectionRect(aRect, bRect)) as {record, list}
  
set tmpClass to class of a1Res
  
  
if tmpClass = record then
    –macOS 10.10, 10.11, 10.12
    
return not (a1Res = {origin:{x:0.0, y:0.0}, |size|:{width:0.0, height:0.0}})
  else if tmpClass = list then
    –macOS 10.13 or later
    
return not (a1Res = {{0.0, 0.0}, {0.0, 0.0}})
  end if
end detectRectanglesCollision

–1から任意の数までのアイテムで、2個ずつの組み合わせのすべての順列組み合わせパターンを計算して返す
–ただし、1×1とか2×2などの同一アイテム同士の掛け合わせを除去するものとする
on retPairPermutationsWithoutSelfCollision(aMax)
  set aList to {}
  
  
repeat with x from 1 to aMax
    repeat with xx from 1 to aMax
      if x is not equal to xx then
        
        
set tmpItem to {x, xx}
        
set a2List to sort1DNumList(tmpItem, true) of me
        
        
if {a2List} is not in aList then
          set the end of aList to a2List
        end if
      end if
      
    end repeat
  end repeat
  
  
return aList
end retPairPermutationsWithoutSelfCollision

–1D List(数値)をsort / ascOrderがtrueだと昇順ソート、falseだと降順ソート
on sort1DNumList(theList as list, aBool as boolean)
  tell current application’s NSSet to set theSet to setWithArray_(theList)
  
tell current application’s NSSortDescriptor to set theDescriptor to sortDescriptorWithKey_ascending_(missing value, aBool)
  
set sortedList to theSet’s sortedArrayUsingDescriptors:{theDescriptor}
  
return (sortedList) as list
end sort1DNumList

★Click Here to Open This Script 

(Visited 42 times, 1 visits today)
Posted in list | Tagged 12.0savvy Keynote NSRect | 1 Comment

Keynoteの最前面の書類の現在のスライドで、表オブジェクトの重なり合い(2つ以上対応)を検出 v2

Posted on 4月 3, 2022 by Takaaki Naganoya

Keynote書類の現在のスライド(ページ)上に存在する表オブジェクトの重なり合いを検出するAppleScriptです。

Cocoa Scripting Course #4のチェックを行なっていたら、表オブジェクトが重なり合っていたページがあってヘコみました(再チェック中です)。

これを自動でチェックするためのAppleScriptを書いてみました。とりあえず、現在表示しているスライド(ページ)を対象に。最終的には、開始と終了のスライドの番号を与えておくと、その間のスライドをすべてチェックできるとよいでしょう。

CocoaのNSRect同士であれば、重なり合いを検出できるので大変便利です。Keynote上の表オブジェクトから、位置情報と大きさの情報を取得すれば、簡単に目的のデータ(配列に入れたNSRect)を作れることでしょう。

ただし、NSIntersectionRectでNSRect同士の衝突検出を行えるとしても、1対1でしかチェックできないようなので、検出された表同士のすべての衝突チェック組み合わせを行うべく、順列組み合わせペア・パターンを計算する部品を急遽作って(以前作った、Permutation計算とは仕様が違うので)、2つずつ表(から作ったNSRect)を取り出して矩形座標の衝突判定を行なっています。

Keynoteの座標系は「左上」が原点座標で、Cocoaの座標系は左下のはずで….macOS 12で左上になったという話もありますが、実戦投入してみたら衝突が発生していないスライドでも衝突が検出されていたので、このあたり修正する必要があるかもしれません。

Keynoteのスライド上の表の配置状況をCocoaのNSRectで表現し、デバッグ用に画像で表示させてみました。重なりをシミュレーションするだけなら、とくに問題はなさそうです。

→ 原因がわかりました。表の座標とサイズから作ったNSRect同士を重なり合い計算するための、順列組み合わせパターン計算ルーチンで1×1とか2×2とかの「同じNSRect同士」の重なりを計算するようなパターンまで出力していたのが原因です。

つまり、現状では「複数の表オブジェクトが入っているスライド」を検出するだけの計算を行なってしまっているようです。

--> {{1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 1}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {3, 5}, {4, 1}, {4, 2}, {4, 3}, {4, 4}, {4, 5}, {5, 1}, {5, 2}, {5, 3}, {5, 4}, {5, 5}}

と計算してしまうところを、

--> {{1, 2}, {1, 3}, {1, 4}, {1, 5}, {2, 1}, {2, 3}, {2, 4}, {2, 5}, {3, 1}, {3, 2}, {3, 4}, {3, 5}, {4, 1}, {4, 2}, {4, 3}, {4, 5}, {5, 1}, {5, 2}, {5, 3}, {5, 4}}

のように、同じアイテム同士の組み合わせになるパターンだけを除外してあげればよかったわけです。自分で資料を作ってみてわかりました。

あとは、3×5と5×3は計算としては同じ意味なので、こういう重複パターンを除去してあげる必要があるのですが…重なりの「個数」を数えるのであるのであればともかく、重なりを「検出」するだけなら重複除去まではする必要がないでしょう。

AppleScript名:現在のスライド上の表オブジェクトの重なり合い(2つ以上対応)を検出 v2.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/04/03
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

tell application "Keynote"
  tell front document
    tell current slide
      set tList to every table
      
      
if length of tList < 2 then return false –複数の「表」がなかったら衝突は発生していない
      
      
–表の座標とサイズによりNSRectangleを作成する
      
set bList to {}
      
      
repeat with i in tList
        set j to contents of i
        
        
tell j
          set {xPos, yPos} to position
          
set aWidth to width
          
set aHeight to height
          
set aRect to makeRect(xPos, yPos, aWidth, aHeight) of me
        end tell
        
        
set the end of bList to aRect
      end repeat
      
      
–作成したNSRectangleの順列組み合わせペア・パターンを作成して、NSRectangle同士の衝突判定を順次行う
      
set aLen to length of bList
      
set permuList to retPairPermutations(aLen) of me
      
set corruptList to {}
      
      
repeat with i in permuList
        copy i to {i1, i2}
        
set rectRes to detectRectanglesCollision(item i1 of bList, item i2 of bList) of me
        
if rectRes = true then return true –表同士の衝突が発生している
      end repeat
      
      
return false –表同士の衝突は発生していない
    end tell
  end tell
end tell

on makeRect(xPos, yPos, aWidth, aHeight)
  return current application’s NSMakeRect(xPos, yPos, aWidth, aHeight)
end makeRect

–NSRect同士の衝突判定
on detectRectanglesCollision(aRect, bRect)
  set a1Res to (current application’s NSIntersectionRect(aRect, bRect)) as {record, list}
  
set tmpClass to class of a1Res
  
  
if tmpClass = record then
    –macOS 10.10, 10.11, 10.12
    
return not (a1Res = {origin:{x:0.0, y:0.0}, |size|:{width:0.0, height:0.0}})
  else if tmpClass = list then
    –macOS 10.13 or later
    
return not (a1Res = {{0.0, 0.0}, {0.0, 0.0}})
  end if
end detectRectanglesCollision

–1から任意の数までのアイテムで、2個ずつの組み合わせのすべての順列組み合わせパターンを計算して返す
on retPairPermutations(aMax)
  set aList to {}
  
  
repeat with x from 1 to aMax
    repeat with xx from 1 to aMax
      set tmpItem to {x, xx}
      
if tmpItem is not in aList then
        set the end of aList to tmpItem
      end if
    end repeat
  end repeat
  
  
return aList
end retPairPermutations

★Click Here to Open This Script 

(Visited 69 times, 1 visits today)
Posted in list | Tagged 12.0savvy Keynote NSRect | 1 Comment

Pages書類内の表の指定ラベルの行を削除

Posted on 2月 14, 2022 by Takaaki Naganoya

Pagesの書類上にある表に対して、指定のラベルを持つ行を削除するAppleScriptです。macOS 12.3beta2+Pages 11.2で動作確認しています。

現在作成中のWebブラウザのScripting本で、各種AppleScript実行環境の一覧表を掲載しているのですが、

それぞれの差別化ポイントとして掲載していたデータのうちの1つが、執筆後に一律で解決できることになり(NSAlertダイアログの最前面表示)、そのデータ行については削除することになりました。

そこで、複数のPages書類に記載した表を一括で削除することになり、AppleScriptを組んで削除することにしました。

必要はありませんでしたが、ヘッダー列が1列だけでなく、複数の列になった場合と、ヘッダーの複数セルが1つにまとめられていた場合への対処も行っておきました。ただし、気休め程度であって、本気で対処したものではありません。

AppleScript名:Pages書類内の表の指定ラベルの行を削除.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/02/14
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

set targRowLabel to "NSAlert ダイアログの最前面表示"

tell application "Pages"
  tell front document
    set tList to every table whose column count = 2
  end tell
end tell

delRowInEveryTable(tList, targRowLabel) of me

on delRowInEveryTable(tList as list, targRowLabel as string)
  tell application "Pages"
    repeat with i in tList
      set j to contents of i
      
      
tell j
        set hCCount to header column count
        
set hRCount to header column count
        
        
–ヘッダーカラムが複数存在している場合に対処?
        
repeat with hc from 1 to hCCount
          tell column hc
            set aList to value of every cell
          end tell
          
          
if targRowLabel is in aList then
            set aRes to search1DList(aList, targRowLabel) of me
            
            
–ヘッダー列に削除対象ラベルが存在しつつ、削除対象ラベルがヘッダー行の範囲ではない場所に出現した場合に削除
            
if (aRes is not equal to false) and (aRes ≥ hRCount) then
              try –ねんのため
                delete row aRes
              end try
            end if
          end if
          
        end repeat
      end tell
    end repeat
    
  end tell
end delRowInEveryTable

on search1DList(aList, aTarg)
  set anArray to current application’s NSMutableArray’s arrayWithArray:aList
  
set anIndex to anArray’s indexOfObject:aTarg
  
if (anIndex = current application’s NSNotFound) or (anIndex > 9.99999999E+8) then
    return false
  end if
  
return (anIndex as integer) + 1 –convert index base (0 based to 1 based)
end search1DList

★Click Here to Open This Script 

(Visited 38 times, 1 visits today)
Posted in list | Tagged 10.15savvy 11.0savvy 12.0savvy Pages | Leave a comment

リストに入れたテキストで、冒頭に入ったマルつき数字をリナンバーする

Posted on 2月 12, 2022 by Takaaki Naganoya

日本語環境限定かもしれませんが、マルつき数字(①②③④⑤⑥⑦⑧⑨….)をさまざまな場所でよく使います。

データにマルつき数字を入れると、順番がわかりやすくてよいのですが、データそのものを入れ替えたときに番号をふり直すという手間がかかってしまいます。これがけっこうな手間になっています(地味に大変)。

そこで、

 {"③AAAAAA", "②BBBBB", "①CCCCC", "⑬DDDDDD", "⑫EEEE", "④FFFF", "⑤GGGG", "⑥HHHH", "⑲IIIII", "⑧JJJJ"}

というデータを本Scriptによって、

{"①AAAAAA", "②BBBBB", "③CCCCC", "④DDDDDD", "⑤EEEE", "⑥FFFF", "⑦GGGG", "⑧HHHH", "⑨IIIII", "⑩JJJJ"}

と、リナンバー処理します。

本処理は、絵文字の削除Scriptの副産物として生まれたもので、マル文字を削除したのちに番号をふり直して付加したところ、たいへん有用性を感じられました。

Keynote、Numbers、Pages…と、同じことができるようにScriptを整備し、CotEditor用にあったほうが便利だろうと考えて、CotEditor用にかきかえた際に、

–> Watch Demo Movie

「ほかのアプリケーションでも使えたほうが便利なので、再利用しやすいように部品化しておこう」

と、Script文でラッピングしてみたものがこれです。

AppleScript名:リストに入れたテキストで、冒頭に入ったマルつき数字をリナンバーする.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/02/12
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

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

set aOffset to 0

set aSelList to {"③AAAAAA", "②BBBBB", "①CCCCC", "⑬DDDDDD", "⑫EEEE", "④FFFF", "⑤GGGG", "⑥HHHH", "⑲IIIII", "⑧JJJJ"}

—データ中に丸つき数字が存在した場合には、最小のものを取得
set aOffset to (getMinimumNumFromNumberWithSign(aSelList) of maruNumKit)

–ユーザーに対して「本当に初期値がこれでいいのか?」をダイアログなどで確認したほうがいい

–Keynoteの表のセルから取得したデータから丸つき数字を除去する
set cList to removeNumberWithSignFromList(aSelList) of maruNumKit

–list中の各アイテムの冒頭に順次丸つき数字を追加する
set dList to {}
set aCount to 0

repeat with i in cList
  set j to convNumToNumWithSign(aCount + aOffset) of maruNumKit
  
set jj to contents of i
  
  
set the end of dList to (j & jj)
  
  
set aCount to aCount + 1
end repeat

return dList
–> {"①AAAAAA", "②BBBBB", "③CCCCC", "④DDDDDD", "⑤EEEE", "⑥FFFF", "⑦GGGG", "⑧HHHH", "⑨IIIII", "⑩JJJJ"}

–1D Arrayを改行コードをデリミタに指定しつつテキスト化
–set outStr to retDelimedText(dList, return) of maruNumKit

–丸つき数字を扱うキット
script maruNumKit
  
  
use AppleScript
  
use framework "Foundation"
  
use scripting additions
  
property parent : AppleScript
  
  
–1~50の範囲の数値を丸つき数字に変換して返す
  
on convNumToNumWithSign(aNum as number)
    if (aNum ≤ 0) or (aNum > 50) then return ""
    
set aStr to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
    
set bChar to character aNum of aStr
    
return bChar
  end convNumToNumWithSign
  
  
  
–1D List上で指定データを検索してヒットしたアイテム番号を返す
  
on search1DList(aList, aTarg)
    set anArray to current application’s NSMutableArray’s arrayWithArray:aList
    
set anIndex to anArray’s indexOfObject:aTarg
    
if (anIndex = current application’s NSNotFound) or (anIndex > 9.99999999E+8) then
      return false
    end if
    
return (anIndex as integer) + 1 –convert index base (0 based to 1 based)
  end search1DList
  
  
  
–1D listのクリーニング
  
on cleanUp1DList(aList as list, cleanUpItems as list)
    set bList to {}
    
repeat with i in aList
      set j to contents of i
      
if j is not in cleanUpItems then
        set the end of bList to j
      else
        set the end of bList to ""
      end if
    end repeat
    
return bList
  end cleanUp1DList
  
  
  
–text in listから丸つき数字を除去する
  
on removeNumberWithSignFromList(aList as list)
    set bList to {}
    
repeat with i in aList
      set j to contents of i
      
set j2 to removeNumberWithSign(j) of me
      
set the end of bList to j2
    end repeat
    
return bList
  end removeNumberWithSignFromList
  
  
  
–文字列から丸つき数字を除去する
  
on removeNumberWithSign(aStr as text)
    set aNSString to current application’s NSString’s stringWithString:aStr
    
return (aNSString’s stringByReplacingOccurrencesOfString:"[\\U000024EA-\\U000024EA\\U00002460-\\U00002473\\U00003251-\\U000032BF\\U000024FF-\\U000024FF\\U00002776-\\U0000277F\\U000024EB-\\U000024F4\\U00002780-\\U00002789\\U0000278A-\\U00002793\\U000024F5-\\U000024FE]" withString:"" options:(current application’s NSRegularExpressionSearch) range:{0, aNSString’s |length|()}) as text
  end removeNumberWithSign
  
  
  
–1D Listに入っているテキストから丸つき数字を抽出して数値化し、最小のものを求める
  
on getMinimumNumFromNumberWithSign(aList)
    set nList to {}
    
    
repeat with i in aList
      set j to contents of i
      
–与えられたテキストのうち、丸つき数字(白)の
      
set j2 to holdNumberWithSignOnly(j) of me
      
set n2List to characters of j2 –複数の丸つき数字が入っている場合に対処
      
      
repeat with ii in n2List
        set jj to contents of ii
        
set tmpNum to decodeNumFromNumWithSign(jj) of me
        
set the end of nList to tmpNum
      end repeat
      
    end repeat
    
    
set anArray to current application’s NSArray’s arrayWithArray:nList
    
set cRes to (anArray’s valueForKeyPath:"@min.self") as integer
    
return cRes
  end getMinimumNumFromNumberWithSign
  
  
  
–指定文字列から丸つき数字のみ抽出する
  
on holdNumberWithSignOnly(aStr as text)
    set aNSString to current application’s NSString’s stringWithString:aStr
    
return (aNSString’s stringByReplacingOccurrencesOfString:"[^\\U000024EA-\\U000024EA\\U00002460-\\U00002473\\U00003251-\\U000032BF\\U000024FF-\\U000024FF\\U00002776-\\U0000277F\\U000024EB-\\U000024F4\\U00002780-\\U00002789\\U0000278A-\\U00002793\\U000024F5-\\U000024FE]" withString:"" options:(current application’s NSRegularExpressionSearch) range:{0, aNSString’s |length|()}) as text
  end holdNumberWithSignOnly
  
  
  
–丸つき数字を数値にデコードする v2
  
on decodeNumFromNumWithSign(aStr as string)
    set numStr1 to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
    
set numStr2 to "❶❷❸❹❺❻❼❽❾❿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴"
    
set numStr3 to "➀➁➂➃➄➅➆➇➈➉"
    
set numStr4 to "➊➋➌➍➎➏➐➑➒➓"
    
set numStr5 to "⓵⓶⓷⓸⓹⓺⓻⓼⓽⓾"
    
    
set nList to {numStr1, numStr2, numStr3, numStr4, numStr5}
    
    
repeat with i in nList
      set numTemp to contents of i
      
if numTemp contains aStr then
        using terms from scripting additions
          set bNum to offset of aStr in numTemp
        end using terms from
        
return bNum
      end if
    end repeat
    
return false
  end decodeNumFromNumWithSign
  
  
–1D Listを指定デリミタをはさみつつテキストに
  
on retDelimedText(aList as list, aDelim as string)
    set aText to ""
    
set curDelim to AppleScript’s text item delimiters
    
set AppleScript’s text item delimiters to aDelim
    
set aText to aList as text
    
set AppleScript’s text item delimiters to curDelim
    
return aText
  end retDelimedText
end script

★Click Here to Open This Script 

(Visited 55 times, 1 visits today)
Posted in list Text | Tagged 10.15savvy 11.0savvy 12.0savvy | 1 Comment

Numbersの表でセル連結箇所が存在していたらすべて連結解除

Posted on 1月 31, 2022 by Takaaki Naganoya

指定のNumbers書類中の指定の表で、セルの連結が行われた箇所が存在していたらすべて連結解除するAppleScriptです。

Numbersの表でセルの連結が存在していると、フィルタ処理などが行えないために、セル連結箇所がないかを調べる手段がないと困ります。でも、そういう便利なコマンドがNumbersのAppleScript用語辞書には存在していないので作りました。

連結箇所が分かれば、個別に連結解除するだけです。ループですべてunmergeします。

動作確認は、M1 Mac mini+macOS 12.3beta+Numbersバージョン11.2で行なっています。


▲処理前 セルが連結されている箇所が複数存在している


▲処理後 すべてのセル結合されている箇所が連結解除された

AppleScript名:指定の表で連結セルがあればすべて分離.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/01/31
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property NSCountedSet : a reference to current application’s NSCountedSet

tell application "Numbers"
  tell front document
    tell active sheet
      tell table 1
        set nList to name of every cell
        
set aRes1 to returnDuplicatesOnly(nList) of me –重複するセルの名称のみピックアップ
        
        
–重複セルを個別に分離
        
repeat with i in aRes1
          set j to contents of i
          
unmerge cell j
        end repeat
      end tell
    end tell
  end tell
end tell

on returnDuplicatesOnly(aList as list)
  set aSet to NSCountedSet’s alloc()’s initWithArray:aList
  
set bList to (aSet’s allObjects()) as list
  
  
set dupList to {}
  
repeat with i in bList
    set aRes to (aSet’s countForObject:i)
    
if aRes > 1 then
      set the end of dupList to (contents of i)
    end if
  end repeat
  
  
return dupList
end returnDuplicatesOnly

★Click Here to Open This Script 

(Visited 48 times, 1 visits today)
Posted in list Object control | Tagged 10.15savvy 11.0savvy 12.0savvy NSCountedSet Numbers | Leave a comment

Numbersの表でセル連結箇所が存在しているかどうかチェック

Posted on 1月 31, 2022 by Takaaki Naganoya

指定のNumbers書類中の指定の表で、セルの連結が行われた箇所が存在しているかどうかチェックするAppleScriptです。

Numbersの表でセルの連結が存在していると、フィルタ処理などが行えないために、セル連結箇所がないかを調べる手段がないと困ります。でも、そういう便利なコマンドはNumbersのAppleScript用語辞書には存在していません。

動作確認は、M1 Mac mini+macOS 12.3beta+Numbersバージョン11.2で行なっています。

セルが連結されている箇所は、セルのnameが重複していることが判明。すべてのセルの「name」を取得して、重複しているものをチェックするとセル連結の有無がわかります。

B3セルのproperties

{vertical alignment:top, row:row “row2” of table 1 of sheet 1 of document id “6ED4F3E1-57BD-4A1E-8E0E-9C781DE3840E” of application “Numbers”, class:cell, font name:”HiraKakuProN-W3″, formatted value:”2 21″, background color:missing value, formula:missing value, name:”B3″, text wrap:true, text color:{0, 0, 0}, alignment:auto align, column:column “field1” of table 1 of sheet 1 of document id “6ED4F3E1-57BD-4A1E-8E0E-9C781DE3840E” of application “Numbers”, format:automatic, font size:10.0, value:”2 21″}

C3セルのproperties

{vertical alignment:top, row:row “row2” of table 1 of sheet 1 of document id “6ED4F3E1-57BD-4A1E-8E0E-9C781DE3840E” of application “Numbers”, class:cell, font name:”HiraKakuProN-W3″, formatted value:”2 21″, background color:missing value, formula:missing value, name:”B3″, text wrap:true, text color:{0, 0, 0}, alignment:auto align, column:column “field2” of table 1 of sheet 1 of document id “6ED4F3E1-57BD-4A1E-8E0E-9C781DE3840E” of application “Numbers”, format:automatic, font size:10.0, value:”2 21″}

AppleScript名:指定の表でセル連結がないかチェック.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/01/31
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property NSCountedSet : a reference to current application’s NSCountedSet

tell application "Numbers"
  tell front document
    tell active sheet
      tell table 1
        set nList to name of every cell
        
set aRes1 to returnDuplicatesOnly(nList) of me
        
return aRes1
        
–> {"B3"}
      end tell
    end tell
  end tell
end tell

on returnDuplicatesOnly(aList as list)
  set aSet to NSCountedSet’s alloc()’s initWithArray:aList
  
set bList to (aSet’s allObjects()) as list
  
  
set dupList to {}
  
repeat with i in bList
    set aRes to (aSet’s countForObject:i)
    
if aRes > 1 then
      set the end of dupList to (contents of i)
    end if
  end repeat
  
  
return dupList
end returnDuplicatesOnly

★Click Here to Open This Script 

(Visited 66 times, 1 visits today)
Posted in list Object control | Tagged 10.15savvy 11.0savvy 12.0savvy NSCountedSet Numbers | 1 Comment

16bitカラー値から明度を取得 v1.1

Posted on 1月 20, 2022 by Takaaki Naganoya

choose colorコマンドやiWorkアプリケーションが返してくる16ビットのカラー値({R,G,B})から明度情報を取得するAppleScriptです。0から1までの値を返し、0に近づくほど暗く、1に近づくほど明るい色であることを表現しています。

色情報同士を比較して、明るい箇所に指定している色データと暗い箇所に指定している色データを、RGB値から自動認識するような処理に使っています。

また、ファイル名から「章」(Chapter)の番号を検出して、実際のツメ(Index)の選択部分を暗い色で塗り直す処理も行なっています。

–> Watch Demo Movie

Pages書類の上に作成したツメ(辞書などの端に印刷されているAからZのインデックス)に対して、ツメのオブジェクトを(座標や形状から)自動認識したあとに、色の塗り分け情報を本ルーチンを用いて自動認識。濃い色を現在の選択箇所の色、明るい(淡い)色を通常の箇所の色情報として扱い、あらかじめツメに指定していた色情報を用いて実際の章構成を反映させてツメのオブジェクト(表)を再構成する処理に必須のものです。

明度情報の取得には、グレースケールに変換してグレー度(whiteComponent)を明度とみなして計算しています。直感的にこちらのほうが、まっとうな処理(HSB色空間の色に変換してからBrightnessを取得)よりもしっくり来る計算結果だったので採用しています。

おまけで、2つの色情報のうちどちらが暗いか、結果をインデックス値で返す処理ルーチンをつけています。これも、選択色と非選択色の自動識別のために必要なものです。

AppleScript名:16bitカラー値から明度を取得 v1.1.scptd
—
–  Created by: Takaaki Naganoya
–  Created on: 2022/01/20
—
–  Copyright © 2022 Piyomaru Software, All Rights Reserved
—

set a1Col to {26148, 65535, 58650}
set a1Col to choose color default color a1Col
set w1Col to calcBrightnessFrom16bitColorList(a1Col) of colorBrightnessKit
–> 0.900838315487

set a2Col to {2966, 23133, 21203}
set a2Col to choose color default color a2Col
set w2Col to calcBrightnessFrom16bitColorList(a2Col) of colorBrightnessKit
–> 0.37399661541–0に近いのでこちらのほうが暗い

set cIndRes to calcColorPairsDarkerCol(a1Col, a2Col) of colorBrightnessKit
–> {2, 1}–暗い順にインデックス値を返す

–色情報から明度を計算するKit。0に近い値が暗い。CMYKやグレースケール値は対象外。RGBのみ
script colorBrightnessKit
  
  
use AppleScript
  
use framework "Foundation"
  
use framework "AppKit"
  
use scripting additions
  
property parent : AppleScript
  
  
property NSColor : a reference to current application’s NSColor
  
property NSString : a reference to current application’s NSString
  
property NSAttributedString : a reference to current application’s NSAttributedString
  
property NSUTF16StringEncoding : a reference to current application’s NSUTF16StringEncoding
  
property NSDeviceWhiteColorSpace : a reference to current application’s NSDeviceWhiteColorSpace
  
  
  
–2つの16ビットカラー値でそれぞれ明度を計算し、暗いものから順にインデックス値を返す
  
on calcColorPairsDarkerCol(aCol as list, bCol as list)
    set b1 to calcBrightnessFrom16bitColorList(aCol) of me
    
set b2 to calcBrightnessFrom16bitColorList(bCol) of me
    
if b1 ≥ b2 then
      return {2, 1} –bColのほうが暗い
    else
      return {1, 2} –aColのほうが暗い
    end if
  end calcColorPairsDarkerCol
  
  
  
–16ビットカラー値から明度を計算
  
on calcBrightnessFrom16bitColorList(colList as list)
    copy colList to {rVal, gVal, bVal}
    
–NSColorを作成
    
set aCol to makeNSColorFromRGBAval(rVal, gVal, bVal, 65535, 65535) of me
    
— グレースケール化
    
set gCol to aCol’s colorUsingColorSpaceName:(NSDeviceWhiteColorSpace)
    
set wComp to gCol’s whiteComponent() –whiteComponentを取得することで擬似的に明度情報を取得  
    
return wComp
  end calcBrightnessFrom16bitColorList
  
  
  
–HTMLカラー値あから明度を計算
  
on calcBrightnessFromHTMLColorCodeStr(aStr as string)
    set {rVal, gVal, bVal} to rgbHex2nunList(aStr) of me
    
–NSColorを作成
    
set aCol to makeNSColorFromRGBAval(rVal, gVal, bVal, 255, 255) of me
    
— グレースケール化
    
set gCol to aCol’s colorUsingColorSpaceName:(NSDeviceWhiteColorSpace)
    
set wComp to gCol’s whiteComponent() –whiteComponentを取得することで擬似的に明度情報を取得  
    
return wComp
  end calcBrightnessFromHTMLColorCodeStr
  
  
  
on makeNSColorFromRGBAval(redValue as integer, greenValue as integer, blueValue as integer, alphaValue as integer, aMaxVal as integer)
    set aRedCocoa to (redValue / aMaxVal) as real
    
set aGreenCocoa to (greenValue / aMaxVal) as real
    
set aBlueCocoa to (blueValue / aMaxVal) as real
    
set aAlphaCocoa to (alphaValue / aMaxVal) as real
    
set aColor to NSColor’s colorWithCalibratedRed:aRedCocoa green:aGreenCocoa blue:aBlueCocoa alpha:aAlphaCocoa
    
return aColor
  end makeNSColorFromRGBAval
  
  
  
  
on decodeCharacterReference(aStr)
    set anNSString to NSString’s stringWithString:aStr
    
set theData to anNSString’s dataUsingEncoding:(NSUTF16StringEncoding)
    
set styledString to NSAttributedString’s alloc()’s initWithHTML:theData documentAttributes:(missing value)
    
set plainText to (styledString’s |string|()) as string
    
return plainText
  end decodeCharacterReference
  
  
  
  
–HTMLコードのRGB 16進数コードを数値リストに変換
  
on rgbHex2nunList(aHexStr)
    –エラーチェック
    
if aHexStr does not start with "#" then return false
    
if length of aHexStr is not equal to 7 then return false
    
set bHex to text 2 thru -1 of aHexStr
    
    
set {rStr, gStr, bStr} to {text 1 thru 2 of bHex, text 3 thru 4 of bHex, text 5 thru 6 of bHex}
    
    
set bList to {}
    
repeat with i in {rStr, gStr, bStr}
      set j to contents of i
      
set the end of bList to aHexStrToNum(j) of me
    end repeat
    
    
return bList
  end rgbHex2nunList
  
  
  
–16進数文字列を10進数数値に変換する
  
on aHexStrToNum(hexStr)
    set hStr to "0123456789ABCDEF"
    
    
set aNum to 0
    
set aLen to length of hexStr
    
    
repeat with i from aLen to 1 by -1
      
      
set aCon to contents of character i of hexStr
      
using terms from scripting additions
        set aVal to (offset of aCon in hStr) – 1
      end using terms from
      
set aNum to aNum + aVal * (16 ^ (aLen – i))
      
    end repeat
    
    
return aNum as integer
  end aHexStrToNum
end script

★Click Here to Open This Script 

(Visited 36 times, 1 visits today)
Posted in Color list | Tagged 10.15savvy 11.0savvy 12.0savvy NSColor | Leave a comment

Pagesで選択中の表のカラム幅を自動調整

Posted on 12月 18, 2021 by Takaaki Naganoya

Pagesの最前面の書類で選択中の表オブジェクトの2列目以降を均等に自動調整するAppleScriptです。

–> Watch Demo

1列目の列幅は変更しません。表全体を選択するのではなく、どこかのセルを選択しておく必要があります。


▲処理前 カラム幅が不均一。表の1つあるいは複数のセルを選択して処理対象を指定


▲処理後 2列目以降が均一に調整される

AppleScript名:Pagesで選択中の表のカラム幅を自動調整
— Created 2021-12-18 by Takaaki Naganoya
— 2021 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

–現在選択中の表オブジェクトを取得
set curTable to returnSelectedTableOnCurrentSlide() of me
if curTable = false then return

–現在選択中の表オブジェクト中の選択範囲中のセルをすべて取得(1D List)
using terms from application "Pages"
  tell curTable
    set cellList to every cell of selection range
  end tell
end using terms from

–2列目から末尾までの列幅を均等に変更する
using terms from application "Pages"
  tell curTable
    set cCount to count every column
    
set cWidth to width of every column
    
    
–表の幅を取得したら、0が返ってきたので、各カラム幅を合計した
    
set aWidth to calcSumFrom1DList(cWidth) of me
    
    
set aveWidth to (aWidth – (first item of cWidth)) / (cCount – 1)
    
    
–いったん幅を少なくしておく(予備動作)
    
–途中で幅がページ幅をオーバーすると最終的な表の幅がおかしくなるので、この処理がないとおかしくなる
    
repeat with i from 2 to cCount
      set width of column i to 10
    end repeat
    
    
–カラム幅を変更する
    
repeat with i from 2 to cCount
      set width of column i to aveWidth
    end repeat
  end tell
end using terms from

–1D List中の数値を合計して返す
on calcSumFrom1DList(aList)
  set anArray to current application’s NSArray’s arrayWithArray:aList
  
return (anArray’s valueForKeyPath:"@sum.self")’s intValue()
end calcSumFrom1DList

–現在のスライド上で選択中の表オブジェクトへの参照を取得する
on returnSelectedTableOnCurrentSlide()
  tell application "Pages"
    tell front document
      try
        return (first table whose class of selection range is range)
      on error
        return false –何も選択されてなかった場合
      end try
    end tell
  end tell
end returnSelectedTableOnCurrentSlide

★Click Here to Open This Script 

(Visited 80 times, 1 visits today)
Posted in list | Tagged 10.15savvy 11.0savvy 12.0savvy Pages | Leave a comment

Keynoteの表の選択中のセルに入っている丸つき数字をインクリメント/デクリメント

Posted on 12月 16, 2021 by Takaaki Naganoya

Keynoteの最前面の書類の現在のスライド上にある表の選択中のセルに入っている丸つき数字(①②③…… )をインクリメント(+1)、デクリメント(ー1)するAppleScriptです。

–> Watch Demo Movie

書籍などに掲載する資料で、参照番号をいじくるツールがどうしても必要になって作ったものです。

macOS標準搭載のスクリプトメニューに入れて実行することを前提にしています。丸つき数字は、

①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿

のみを前提にして処理しています。その他の、

❶❷❸❹❺❻❼❽❾❿⓫⓬⓭⓮⓯⓰⓱⓲⓳⓴
➀➁➂➃➄➅➆➇➈➉
➊➋➌➍➎➏➐➑➒➓
⓵⓶⓷⓸⓹⓺⓻⓼⓽⓾

については無視しています。

Keynote v11.2+macOS 12.1betaで作成&動作確認していますが、Keynoteのバージョンにはとくに(バグのあるバージョンでなれけば)依存している機能はありません。


▲選択範囲のセルに入っている丸つき数字のインクリメント(①②③→②③④)


▲選択範囲のセルに入っている丸つき数字のデクリメント(②③④→①②③)

AppleScript名:選択中の表の指定行・列のマル付き数字のインクリメント(+1).scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/12/16
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.7" — macOS 10.13 or later
use framework "Foundation"
use scripting additions

–現在選択中の表オブジェクトを取得
set curTable to returnSelectedTableOnCurrentSlide() of me
if curTable = false then return

–現在選択中の表オブジェクト中の選択範囲中のセルをすべて取得(1D List)
using terms from application "Keynote"
  tell curTable
    set cellList to every cell of selection range
  end tell
end using terms from

–list中の各アイテムの冒頭に順次丸つき数字を追加する
using terms from application "Keynote"
  tell curTable
    repeat with i in cellList
      –選択範囲のセルの値を取り出す
      
set aVal to value of i
      
set vList to characters of (aVal as string)
      
      
–1文字ずつに分割してループ
      
set tmpOut to ""
      
repeat with ii in vList
        set jj to contents of ii
        
        
–丸付き数字の検出
        
set tmpR to holdNumberWithSignOnly(jj) of me
        
if tmpR is equal to jj then
          –丸付き数字を数値にデコード
          
set tmpNum to decodeNumFromNumWithSign(tmpR) of me
          
          
–数値をインクリメント
          
if tmpNum ≤ 50 then
            set tmpNum to tmpNum + 1 –インクリメント
          end if
          
          
–数値を丸付き数字にエンコード
          
set tmpR to convNumToNumWithSign(tmpNum) of me
          
set tmpOut to tmpOut & tmpR
        else
          set tmpOut to tmpOut & jj
        end if
      end repeat
      
      
set value of i to tmpOut
    end repeat
  end tell
end using terms from

–1~50の範囲の数値を丸つき数字に変換して返す
on convNumToNumWithSign(aNum as number)
  if (aNum ≤ 0) or (aNum ≥ 50) then return ""
  
set aStr to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
  
set bChar to character aNum of aStr
  
return bChar
end convNumToNumWithSign

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

–丸つき数字を数値にデコードする v2(簡略版)
on decodeNumFromNumWithSign(aStr as string)
  set numStr1 to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
  
  
if numStr1 contains aStr then
    using terms from scripting additions
      set bNum to offset of aStr in numStr1
    end using terms from
    
return bNum
  end if
  
return false
end decodeNumFromNumWithSign

–現在のスライド上で選択中の表オブジェクトへの参照を取得する
on returnSelectedTableOnCurrentSlide()
  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
        
        
return theTable
        
      end tell
    end tell
  end tell
end returnSelectedTableOnCurrentSlide

★Click Here to Open This Script 

AppleScript名:選択中の表の指定行・列のマル付き数字のデクリメント(ー1).scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/12/16
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.7" — macOS 10.13 or later
use framework "Foundation"
use scripting additions

–現在選択中の表オブジェクトを取得
set curTable to returnSelectedTableOnCurrentSlide() of me
if curTable = false then return

–現在選択中の表オブジェクト中の選択範囲中のセルをすべて取得(1D List)
using terms from application "Keynote"
  tell curTable
    set cellList to every cell of selection range
  end tell
end using terms from

–list中の各アイテムの冒頭に順次丸つき数字を追加する
using terms from application "Keynote"
  tell curTable
    repeat with i in cellList
      –選択範囲のセルの値を取り出す
      
set aVal to value of i
      
set vList to characters of (aVal as string)
      
      
–1文字ずつに分割してループ
      
set tmpOut to ""
      
repeat with ii in vList
        set jj to contents of ii
        
        
–丸付き数字の検出
        
set tmpR to holdNumberWithSignOnly(jj) of me
        
if tmpR is equal to jj then
          –丸付き数字を数値にデコード
          
set tmpNum to decodeNumFromNumWithSign(tmpR) of me
          
          
–数値をデクリメント
          
if tmpNum > 1 then
            set tmpNum to tmpNum – 1 –デクリメント
          end if
          
          
–数値を丸付き数字にエンコード
          
set tmpR to convNumToNumWithSign(tmpNum) of me
          
set tmpOut to tmpOut & tmpR
        else
          set tmpOut to tmpOut & jj
        end if
      end repeat
      
      
set value of i to tmpOut
    end repeat
  end tell
end using terms from

–1~50の範囲の数値を丸つき数字に変換して返す
on convNumToNumWithSign(aNum as number)
  if (aNum ≤ 0) or (aNum ≥ 50) then return ""
  
set aStr to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
  
set bChar to character aNum of aStr
  
return bChar
end convNumToNumWithSign

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

–丸つき数字を数値にデコードする v2(簡略版)
on decodeNumFromNumWithSign(aStr as string)
  set numStr1 to "①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟㊱㊲㊳㊴㊵㊶㊷㊸㊹㊺㊻㊼㊽㊾㊿"
  
  
if numStr1 contains aStr then
    using terms from scripting additions
      set bNum to offset of aStr in numStr1
    end using terms from
    
return bNum
  end if
  
return false
end decodeNumFromNumWithSign

–現在のスライド上で選択中の表オブジェクトへの参照を取得する
on returnSelectedTableOnCurrentSlide()
  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
        
        
return theTable
        
      end tell
    end tell
  end tell
end returnSelectedTableOnCurrentSlide

★Click Here to Open This Script 

(Visited 63 times, 1 visits today)
Posted in list Text | Tagged 10.15savvy 11.0savvy 12.0savvy Keynote | Leave a comment

Post navigation

  • Older posts

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

Google Search

Popular posts

  • AppleScriptによるWebブラウザ自動操縦ガイド
  • macOS 13, Ventura(継続更新)
  • ドラッグ&ドロップ機能の未来?
  • macOS 12.x上のAppleScriptのトラブルまとめ
  • PFiddlesoft UI Browserが製品終了に
  • macOS 12.3 beta 5、ASの障害が解消される(?)
  • SF Symbolsを名称で指定してPNG画像化
  • 新刊発売:AppleScriptによるWebブラウザ自動操縦ガイド
  • macOS 12.3 beta4、まだ直らないASまわりの障害
  • macOS 12.3上でFinder上で選択中のファイルをそのままオープンできない件
  • Safariで表示中のYouTubeムービーのサムネイル画像を取得
  • macOS 12のスクリプトエディタで、Context Menu機能にバグ
  • Pixelmator Pro v2.4.1で新機能追加+AppleScriptコマンド追加
  • 人類史上初、魔導書の観点から書かれたAppleScript入門書「7つの宝珠」シリーズ開始?!
  • CotEditor v4.1.2でAppleScript系の機能を追加
  • macOS 12.5(21G72)がリリースされた!
  • UI Browserがgithub上でソース公開され、オープンソースに
  • Pages v12に謎のバグ。書類上に11枚しか画像を配置できない→解決
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた

Tags

10.11savvy (1102) 10.12savvy (1243) 10.13savvy (1391) 10.14savvy (586) 10.15savvy (434) 11.0savvy (274) 12.0savvy (174) 13.0savvy (34) CotEditor (60) Finder (47) iTunes (19) Keynote (97) NSAlert (60) NSArray (51) NSBezierPath (18) NSBitmapImageRep (21) NSBundle (20) NSButton (34) NSColor (51) NSDictionary (27) NSFileManager (23) NSFont (18) NSImage (42) NSJSONSerialization (21) NSMutableArray (62) NSMutableDictionary (21) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (118) NSURL (97) NSURLRequest (23) NSUTF8StringEncoding (30) NSUUID (18) NSView (33) NSWorkspace (20) Numbers (55) Pages (36) Safari (41) Script Editor (20) WKUserContentController (21) WKUserScript (20) 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年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