Numbersの書類上で選択中のセル内の日付形式データがあったら、yearを+1(インクリメント)するAppleScriptです。macOS 15.4beta+Numbers 14.3で動作確認していますが、OSバージョンおよびNumbersのバージョンに依存する部分はありません。
ものすごくつまらなくて、ものすごく用途が狭いScriptですが、実際に書いてみたら意外と手間取る感じでした。
当然、+1するだけではなくー1する機能も作ってあり、呼び出し部分を差し替えればー1するようになります。macOS標準搭載のスクリプトメニューに入れて実行することを想定しています。
AppleScript名:選択範囲のdateの年を+1する.scptd |
— – Created by: Takaaki Naganoya – Created on: 2025/03/10 — – Copyright © 2025 Piyomaru Software, All Rights Reserved — use AppleScript version "2.4" use framework "Foundation" use scripting additions tell application "Numbers" tell front document tell active sheet try set theTable to first table whose class of selection range is range set cellList to cell of selection range of theTable set valList to value of cell of selection range of theTable set aLen to length of cellList on error display notification "Numbers: There is no selection" return end try set bValList to {} repeat with i in valList set j to contents of i set aClass to class of j if aClass = date then set j to incremenetYearOf(j) of me end if set the end of bValList to j end repeat repeat with i from 1 to aLen set aVal to contents of item i of bValList set aCell to contents of item i of cellList ignoring application responses set value of aCell to aVal end ignoring end repeat end tell end tell end tell on incremenetYearOf(aDate) set {bYear, bMonth, bDate} to {year of aDate, month of aDate, day of aDate} set bYear to bYear + 1 set {year of aDate, month of aDate, day of aDate} to {bYear, bMonth, bDate} return aDate end incremenetYearOf on decremenetYearOf(aDate) set {bYear, bMonth, bDate} to {year of aDate, month of aDate, day of aDate} set bYear to bYear – 1 set {year of aDate, month of aDate, day of aDate} to {bYear, bMonth, bDate} return aDate end decremenetYearOf |