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

月: 2021年11月

FM-1グランプリで仕事効率化部門の部門準賞を獲得!

Posted on 11月 28, 2021 by Takaaki Naganoya

FileMaker Proの「すごいデータベース」のコンテストであるFM-1グランプリにおいて、Piyomaru Softwareの応募作品「FileMaker PowerPack」が、予選を通過し、決勝において仕事効率化部門の部門準賞を獲得いたしました。

FileMaker PowerPackは、CotEditor PowerPackと同様、Cocoa ScriptingのパワーをFileMaker Proユーザーに体感していただく技術的なデモンストレーションであり、かつ日常的にデータベース用のデータ作成などの作業に従事する人たちが便利と感じる(のではないか)という内容のScriptを収録したScriptサンプルデータベースに仕上がっています。

データベース上にサンプルデータを入れ、その場で実行して結果を確認できるようになっています。

内容はあっさり読めるように書いてあるものが多いので、入門用に見えてしまうかもしれませんが……実際にAppleScriptを「書ける」人間が読むと顔をひきつらせるような内容のものが多々入っています。作った本人としては「これを見て書けるようになるとは思わない」というレベル設定です。超絶レベルではないものの、アクロバティックなものが多いので。

技術的にも度肝を抜くような内容であり、178本のScriptを収録してはいるものの、本作品はあくまでFileMaker Pro上で動作するAppleScriptのコードなわけで、「ド派手で巨大で存在感はあるものの、さすがに大賞はとらないだろう」という味付け。本作品のレビュー記事は、文字数からBlog側で単純計算した読了所要時間が23分という大作です(通常の8倍のボリウム)。

それでも、FM-1グランプリの運営方針である「きちんと内容をチェックする詳細なレビュー」が行われおり、日本国内のFileMaker Proコミュニティのレベルを内外に示したという意味において、よそで真似できない「まっとうな」骨太のコンテストであったことを痛感。運営に携わられたお3方、関連スポンサー企業の方々に敬意を表します。

というわけで、このFileMaker PowerPackの書き換え方法や利用方法などを解説した「FileMaker PowerPack活用ガイド」を近日発刊予定です。技術的なレベルを下げて解説し、久しぶりにAppleScriptにさわるという方向けにレベル設定しています。完全理解というレベルでなくても、必要な書き換えはできるだろうという内容を目指しています。

そして、自分で作った作品の作者自身の解説のはずなのに、自分で書いていてとても大変です。「誰だ、こんなもの作ったのは?」という悪態をついてしまうほどですが、それは自分のことなので自業自得というところです。

Posted in news | Tagged FileMaker Pro | Leave a comment

選択中の表の指定行・列のマル付き数字リナンバー v2

Posted on 11月 27, 2021 by Takaaki Naganoya

Keynote書類の現在表示中のスライド(ページ)中の選択中の「表」において、指定の行、指定のヘッダー列以降のセルに対して、(1)丸つき数字の削除 (2)丸つき数字の最小値の計算 を行い、丸つき数字の番号降り直しの開始値をユーザーに確認したうえで、丸つき数字部分のみのリナンバーを行います。

本ScriptはmacOS 12+Keynote v11.2で作成・動作確認を行なってあります。それほどOSおよびKeynoteのバージョンに依存するような処理は行なっていないため、上記以外のOSおよびKeynoteのバージョンの組み合わせでも動くと思います。

–> Watch Demo Movie

初期状態では、

と、丸つき数字のナンバリングが項目の入れ替えなどで正しく並んでいない状態を想定しています。

リナンバー対象の表を選択した状態で本Scriptを実行すると、

リナンバー対象行の問い合わせを行います。一番左の列のデータを抽出して選択させます。この場合には、「名称」を選択します。

次に、リナンバー対象データの列指定を行います。指定列「以降」から「末尾」までをリナンバー処理対象とみなします。この場合には「名称」を選択します。

最後に、丸つき数字のリナンバー開始数値を確認します。

すでに、対象範囲のデータを取り出して丸つき数字の最小値については計算してあるので、その確認のためにダイアログ入力を求めます。推測した数値でよければOKを、修正の必要があれば数値を変更したうえでOKボタンをクリック。

適切に処理が行われれば、丸つき数字部分のリナンバーが完了することでしょう。

AppleScript名:選択中の表の指定行・列のマル付き数字リナンバー v2.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/11/26
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—
use AppleScript version "2.7" — macOS 10.13 or later
use framework "Foundation"
use scripting additions

set aOffset to 0

–選択中のKeynote書類上の表への参照を取得する
set aTable to returnSelectedTableOnCurrentSlide() of me

if aTable = false then
  display notification "No selected table on Keynote document"
  
return
end if

–行選択
using terms from application "Keynote"
  tell aTable
    tell column 1
      set aList to value of every cell
    end tell
  end tell
end using terms from

set a2List to cleanUp1DList(aList, missing value) of me
set aRes to choose from list a2List with prompt "リナンバー対象の行選択"
set a2Res to search1DList(a2List, first item of aRes) of me

–列選択
using terms from application "Keynote"
  tell aTable
    tell row a2Res
      set bList to value of every cell
    end tell
  end tell
end using terms from

set b2List to cleanUp1DList(bList, missing value) of me
set bRes to choose from list b2List with prompt "リナンバー対象の列選択(ヘッダー末尾列)"
set b2Res to search1DList(b2List, first item of bRes) of me

–リナンバー対象のデータを取得(対象データのみ抽出)
using terms from application "Keynote"
  tell aTable
    tell row a2Res
      set bList to value of cells (b2Res + 1) thru -1
    end tell
  end tell
end using terms from

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

–一応、ユーザーに推測した開始値でよいか確認を取る
set dRes to text returned of (display dialog "丸つき数字の開始値:" default answer (aOffset as string))
try
  set aOffset to (dRes as number) – 1
on error
  set aOffset to 0
end try

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

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

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

–リナンバー対象のセルをリナンバーした丸つき数字+内容で置換
set aCount to 1
using terms from application "Keynote"
  tell aTable
    tell row a2Res
      repeat with i from (b2Res + 1) to ((length of bList) + 1)
        set value of cell i to contents of item aCount of dList
        
set aCount to aCount + 1
      end repeat
    end tell
  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 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

–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

★Click Here to Open This Script 

Posted in list Number Text | Tagged 10.15savvy 11.0savvy 12.0savvy Keynote | 1 Comment

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

Posted on 11月 26, 2021 by Takaaki Naganoya

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

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

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

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

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

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

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

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

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

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

★Click Here to Open This Script 

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

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

Posted on 11月 26, 2021 by Takaaki Naganoya

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

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

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

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

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

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

★Click Here to Open This Script 

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

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

Posted on 11月 26, 2021 by Takaaki Naganoya

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

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

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

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

★Click Here to Open This Script 

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

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

Posted on 11月 26, 2021 by Takaaki Naganoya

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

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

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

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

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

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

★Click Here to Open This Script 

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

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

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

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

★Click Here to Open This Script 

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

集中モード(Don’t Disturb Mode)に設定する

Posted on 11月 16, 2021 by Takaaki Naganoya

macOS 12.x上で集中モード(Don’t Disturb Mode)に設定するAppleScriptです。

Shortcutsにその機能があるので、AppleScriptから呼ぶことになるでしょう。使っていると「日本語AppleScript」みたいな違和感の塊のようなショートカット.app。「おやすみモードをオフ時までオンにする」とか、無理に日本語にしないで英語にしてあったほうがまだ分かりやすいと思います。

この「集中モード」という機能についても、画面上で「おやすみモード」と表現されていたり「集中モード」と表現されていたり、いまひとつ機能を表す言葉のレベルに戸惑いを感じます。それとも、自分が何か根本的に勘違いしている箇所があるものでしょうか。

インストール+実行ルーチンを呼ぶことで、このショートカット・ワークフローがMac上に存在していなければインストールし、呼び出しを行います。


▲実行前


▲実行後

AppleScript名:Don’t Disturb Shortcuts v2.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/11/01
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—

set aName to "PIYO_Don’t Disturb" –Shortcut名称
set aURL to "https://www.icloud.com/shortcuts/cf960093816e4c7fb8d23c10e8820790" –共有URL
set sRes to installAndRunShortcuts(aName, aURL) of me

–Install Shortcut and run it
on installAndRunShortcuts(aName, aURL)
  tell application "Shortcuts Events"
    set n1List to name of every shortcut
  end tell
  
  
if n1List does not contain aName then
    display notification "Plese Install my Shortcuts workflow"
    
open location aURL
  end if
  
  
repeat 100 times
    tell application "Shortcuts Events"
      set n2List to name of every shortcut
    end tell
    
    
if n2List contains aName then
      exit repeat
    end if
    
    
delay 0.5
  end repeat
  
  
if n2List does not contain aName then
    display dialog "I can’t run my Shortcuts because you canceled installing"
    
return false
  end if
  
  
  
tell application "Shortcuts Events"
    run shortcut aName
    
return true
  end tell
end installAndRunShortcuts

★Click Here to Open This Script 

Posted in System | Tagged 12.0savvy Shortcuts Shortcuts Events | Leave a comment

FM-1グランプリにFileMaker PowerPackを出品

Posted on 11月 15, 2021 by Takaaki Naganoya

FileMaker Proの作品コンテスト「FM-1グランプリ」の第2回予選を通過した「FileMaker PowerPack」を、内容拡充し第3回予選に再応募しました。

CotEditorのPowerPackにつづく、FileMaker ProのPowerPack。178本のAppleScriptを収録した、FileMaker Proに組み込んで動かすと便利そうなものを収録したサンプル集です。

Cocoa Scriptingのデモンストレーションを行うフリー配布ソリューションです。

FileMaker ProとAppleScriptなので、相性抜群! 楽勝で作れるに違いない!

……そんなことを考えていた時期が自分にもありました。

しかし、割と前代未聞のトラブルに遭遇。苦労話にはことかかないありさまです。だいたい、内容がなかなか決まらずに企画段階でかなり困っていました。

ここでは、お気楽そうに見える見た目とはまったく異なる技術的な内容について記すこととします。

FM独自のAppleScriptランタイム環境が大変

FileMaker ProのAppleScriptランタイム環境は独特のもので、ランタイム名を取得しても「FileMaker Pro」と独自の名前が返ってきます。Vanilla AppleScriptについては環境の違いにともなう「差異」は感じないところですが、Cocoa Scriptingを行うと「まったくの別物」であることを痛感できます。

FileMaker Pro内蔵のスクリプトステップ「AppleScriptを実行」は、実行したAppleScriptが生成したオブジェクトがメモリ上に常駐したりしません。実行後、即座にメモリ上からパージされるようです。ARC的な「使わなくなって時間がたったから自動で消しとくね!」という挙動とはまるっきり違います。

このことで、OS側から各種Notificationを受信するようなもの(USBメモリがマウントされたらAppleScriptを実行させるなど)は、瞬時にクラッシュ。NSTimerでタイマーを生成してタイマ割り込み処理を行おうとするとクラッシュ!

さらに、標準的なランタイム環境(スクリプトエディタ、Script Menu)で実行したときには発生しないトラブルが山のように発生します。

とくに、CoreImageの機能を呼び出して画像処理を行おうとした場合には、明示的にメインスレッドでの処理を指定する必要があり、これに気づくまではまったく画像フィルタ処理ができない始末。FileMaker PowerPackでは無駄にCoreImageのフィルタ呼び出しプログラムばかり60本ぐらい突っ込んでありますが、このCoreImageの処理で問題のある挙動を示すものがないか全数チェックしたという次第です。

Cocoa Scriptingについては、おそらくメーカー側でもノーチェックの部分なので、調べられる機会に調べておいたほうが得策です。

今回のFileMaker PowerPackでいろいろ余計なノウハウがたまりましたが、osascriptなどのランタイム環境と比べてもずいぶん風変わりなCocoa Scripting環境であることを意識しておく必要があることでしょう。

FileMaker PowerPackには目下178のScriptを入れてあり、FileMaker Pro DB上のサンプルデータをもとにデータ処理を行い、結果がある場合にはDB上に結果を描き戻すようになっています。

今回、さまざまなテストを重ね、「極力FileMaker Pro内蔵のAppleScript実行環境を利用しない」ことが問題解決の近道であることを痛感しました。できるだけ、FileMaker Proの外部に補助アプレットを用意して、そちらでCocoa Scriptingの処理を行うべきです。まして、タイマー処理やNotificationの受信処理などはFileMaker Pro内では行えないため、FM内では最低限の処理にとどめ、処理本体を外部に出すべきでしょう。

macOS 12のFramework再編の影響も

macOS 12で行われたFramework再編の影響も受けました。PDFKitの機能を利用する場合、macOS 11までであれば、

use framework "QuartzCore"

と記述していましたが、macOS 12では、

use framework "PDFKit"

と記述する必要があります。

macOS 11までのOSと、macOS 12以降のOSにそれぞれ対応するライブラリを書いて、実行時のOSバージョンを検出して呼び出しを切り替える処理をスクリプトエディタ上で動作確認してあったのですが、これをそのままFileMaker Proのランタイムに持っていくとコンパイル(構文確認)をパスしません。

仕方なく、macOS 11までのScriptと、macOS 12以降のScriptで別々のものに分ける必要がありました。

自称・世界最小の簡易形態素解析エンジン「easyJParse」のFM環境への移植

さまざまなランタイム環境で動作する必要のある、Piyomaru Softwareによる世界最小の簡易形態素解析エンジン「easyJParse」を、このFileMaker PowerPackに組み込んでいます。

このeasyJParseは初出時には80行程度、現在でも100行そこそこという超小型の形態素解析プログラムであり、自然言語(主に日本語)によるコマンドを分解するために開発したものです(飛行機の中でも動かすべく、REST APIで外部のサービスを呼び出したりはしていません)。

当初、easyJParseがFileMaker Proランタイム上で動かず、けっこう焦りましたが……いつもの「ソート方向指定」の「ascending」とか「descending」などのキーワードがFMの予約語と衝突していただけでした。

このeasyJParseが動くことで、FileMaker Pro上でTanzaku的な自然言語によるコマンド指定ソリューションが動きまくるはずですが、32KBまでのScriptしかホスティングできないという制限が地道に大変そうであります。

FM-1 GPにFileMaker選手権2021と結果発表が相次ぐ

ウチの検証環境(Intel+M1 Mac mini)でテストした範囲では問題ないことを確認していましたが、どうもM1 MacBook+Retina Display環境では検証できないので、その環境ではいろいろ問題に遭遇していたようです。問題の洗い出しを行えたことは前向きにとらえるべきですが、その環境がないので事前にチェックすることは不可能です。

# M1のRetina Display+MacBook環境が手元にないのでコンテストに応募したわけで…

肝心の総合結果発表は11月27日。大賞を取ることは難しそうですが、予選を通過したため何かいただけそうです。噂によればFileMaker選手権2021も近い日程で結果が発表されるとかしないとか。こちらにも応募はしているため、せめて参加賞ぐらいはいただきたいものです(モバイルバッテリーだったか)。

FileMaker PowerPackについては、その内容を解説し、書き換えるためのガイドを行う書籍を近日発行予定です。さらに、Cocoa Scripting的な立ち入った解説を行うものも計画しています。

これらの付録に、「FM-1グランプリ戦記」をつける予定です。

Posted in news | Tagged 12.0savvy FileMaker Pro | Leave a comment

AS Publisher v18–> v19

Posted on 11月 7, 2021 by Takaaki Naganoya

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

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

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

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

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

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

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

話を戻しましょう。

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

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

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

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

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

property quotChar : string id 34

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

set a to path to me

set pName to "com.apple.ScriptEditor2"

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

set tabChar to string id 9

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

set TIDsList_ref to a reference to TIDsList

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

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

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

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

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

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

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

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

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

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

on makeEncodedScript(contText)
  (*

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

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

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

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

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

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

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

–ファイルの追記ルーチン「write_to_file」
–追記データ、追記対象ファイル、boolean(trueで追記)
on write_to_file(this_data, target_file, append_data)
  tell current application
    try
      set the target_file to the target_file as text
      
set the open_target_file to open for access file target_file with write permission
      
if append_data is false then set eof of the open_target_file to 0
      
write this_data to the open_target_file starting at eof
      
close access the open_target_file
      
return true
    on error error_message
      try
        close access file target_file
      end try
      
return error_message
    end try
  end tell
end write_to_file

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

★Click Here to Open This Script 

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

FileMaker Pro Scripting Book with AppleScriptをアップデート

Posted on 11月 4, 2021 by Takaaki Naganoya

FileMaker ProのAppleScriptからの操作を詳細に解説した電子書籍「FileMaker Pro Scripting Book with AppleScript」(日本語版)をアップデートしました。

macOS 12に合わせた内容のアップデート、v1.2までに説明されていなかった内容の補完、および別冊付録リファレンスをまとめています。

すでに購入された方は、購入ページからの再ダウンロードで入手可能です。

→ FileMaker Pro Scripting Book with AppleScript オンラインブックストア(BOOTH)

Posted in Books news PRODUCTS | Tagged 12.0savvy FileMaker Pro | Leave a comment

Shortcuts Eventsでショートカットのインストール+実行

Posted on 11月 1, 2021 by Takaaki Naganoya

macOS 12で標準搭載された「ショートカット.app」(Automatorを置き換える簡易ワークフロー構築・実行ツール)を操作して(実際にはGUIなしのShortcuts Events.app)、自分がiCloud上で共有しているショートカット・ワークフローのインストールと実行を行わせるAppleScriptです。

ショートカット・ワークフローはローカルではなくiCloud上に置かれています。それらは「名前」で識別できますが、ユニークなIDが振られているわけではありません。ものすごく不満ですが、一応識別できることにしましょう。

ショートカット・ワークフローは「共有」することが可能で、とくに「リーディングリストで共有」すると、iCloud上の生URLが得られる(SafariのURL欄に表示される)ため、このURL情報を共有すれば「指定のショートカット・ワークフローが存在していない場合にはiCloud上からインストールさせる」という処理が可能になります。

# このあたり、まだ試行錯誤中なので「現時点ではこういう運用をしている」という程度です

今日確認したら、「ファイル」メニューの「共有」に「iCloudリンクをコピー」という項目がありました。

リンクをコピーする機能を入れるなら「編集」メニューではないのかと思わないではないですが、機能的にはこちらがシンプルなのでご利用ください。

お使いの環境に指定のショートカット・ワークフローがインストールされていない場合には、インストールを求めます。ただ、単なる「名称」でしかチェックしていないのと、あらかじめ「同じ名前で内容が違うショートカット」が存在していたら、「インストールずみ」と判定してしまうので、一意に識別できるユニークな識別子がショートカット・ワークフローについていないのはどうかと思います。入手先のiCloud URLでもよいのですが、、、、

# 一応、コンピュータ上で互いを識別するための「id」は持っています

ここで、インストールを行わなかった場合には、それを検出してダイアログ表示します。

AppleScript名:Shortcuts Eventsでショートカットのインストール+実行.scpt
—
–  Created by: Takaaki Naganoya
–  Created on: 2021/11/01
—
–  Copyright © 2021 Piyomaru Software, All Rights Reserved
—

set aName to "ASTEST3" –Shortcut名称
set aURL to "https://www.icloud.com/shortcuts/e788482535704922aaa9f617491353b2" –共有URL
set sRes to installAndRunShortcuts(aName, aURL) of me

–Install Shortcut and run it
on installAndRunShortcuts(aName, aURL)
  tell application "Shortcuts Events"
    set n1List to name of every shortcut
  end tell
  
  
if n1List does not contain aName then
    display notification "Plese Install my Shortcuts workflow"
    
open location aURL
  end if
  
  
tell application "Shortcuts Events"
    set n2List to name of every shortcut
  end tell
  
  
if n2List does not contain aName then
    display dialog "I can’t run my Shortcuts because you canceled installing"
    
return false
  end if
  
  
tell application "Shortcuts Events"
    run shortcut aName
    
return true
  end tell
end installAndRunShortcuts

★Click Here to Open This Script 

Posted in Shortcuts Workflow | Tagged 12.0savvy Shortcuts Shortcuts Events | 1 Comment

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

Google Search

Popular posts

  • macOS 13, Ventura(継続更新)
  • アラートダイアログ上にWebViewで3Dコンテンツを表示(WebGL+three.js)v3
  • UI Browserがgithub上でソース公開され、オープンソースに
  • macOS 13 TTS Voice環境に変更
  • Xcode 14.2でAppleScript App Templateを復活させる
  • 2022年に書いた価値あるAppleScript
  • ChatGPTで文章のベクトル化(Embedding)
  • 新発売:AppleScriptからSiriを呼び出そう!
  • iWork 12.2がリリースされた
  • 従来と異なるmacOS 13の性格?
  • 新発売:CotEditor Scripting Book with AppleScript
  • macOS 13対応アップデート:AppleScript実践的テクニック集(1)GUI Scripting
  • AS関連データの取り扱いを容易にする(はずの)privateDataTypeLib
  • macOS 13でNSNotFoundバグふたたび
  • macOS 12.5.1、11.6.8でFinderのselectionでスクリーンショット画像をopenできない問題
  • ChatGPTでchatに対する応答文を取得
  • 新発売:iWork Scripting Book with AppleScript
  • Finderの隠し命令openVirtualLocationが発見される
  • macOS 13.1アップデートでスクリプトエディタの挙動がようやくまともに
  • あのコン過去ログビューワー(暫定版)

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1390) 10.14savvy (586) 10.15savvy (434) 11.0savvy (277) 12.0savvy (185) 13.0savvy (55) 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
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC