0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ショートカットappが「ヘルパーアプリケーション~~」と言い出して使えないので、applescriptでどうにかする。

Last updated at Posted at 2023-08-20

⚠️mac限定だと思います。iphoneでも「ヘルパーアプリケーション~~」というerrorはあるらしいですが、幸い自分はmacでなったので、解決はできずとも、問題の回避ができました。

内容

macでショートカットを実行すると、「ヘルパーアプリケーションと通信できませんでした。」と出て強制終了され、ショートカットアプリが使い物にならなくなりました。

原因は何か考えた時、おそらくですが、macをクリーンインストールする際にicloud連携を切り忘れたことだと思います。
icloudに入り直したり、セーフブートなど色々やりましたが解決できず。
問題の解決は諦めることに。
で、少し使っていると、エラーを吐くまでに一瞬の間時間があり、すごく短い処理ならエラーの前に終わって、普通に実行できることがわかりました。
そのため、苦肉の策として、applescriptでappを作って、それを実行することにしました。

  1. appを作る。
  • スクリプトエディタを開き、新規作成
  • applescriptでやりたいことを書いて「ファイル」→「書き出す」
  • 名前,保存場所を適当に変え、「ファイルフォーマット」を「アプリケーション」にして保存
  1. ショートカットから起動
  • 新規にショートカットを作成
  • 「appを開く」を追加
  • appの部分で、さっき作ったものを選択

以上で実行できるようになります。
問題点は

  • ショートカットのGUIが使用できない。
  • ショートカットからの変数受け渡しができない。

ショートカットのGUIに関してはapplescriptで似たようなことを簡単にできるので、あまり問題にはならないかと思います。
変数の受け渡しができない、これは自分はもうしょうがないので、クリップボードを挟んでどうにかしました。

ここまで見て、「shellで実行」したり「applescriptで実行」でいいのではと思われるかもですが、これだと実行はショートカットの判定になり、途中で切断されてしまいます。

applescriptでの色々

実際のコードで使ったapplescriptのいろいろです。

  • 実行画面なしでshellscriptを実行
    do shell script "cd ~~"

  • 結果を変数に代入
    set value1 to do shell script ""

  • ターミナルでwindow開いて実行

    tell application "Terminal"
    	activate
    	do script with command "conda activate " & mySelect
    end tell
    
  • 文字列を区切り文字(repStrに入れたもの)で区切ってリストに
    http://www.adg7.com/takenote_b/2009/03/06applescripts-text-item-delimiters.html

    set repStr to " "
    set OriginalDelimiters to AppleScript's text item delimiters
    --元々の区切り文字を保存しておく。決まり事として必ず使う
    set AppleScript's text item delimiters to {repStr} --区切り文字を" "にする
    set value1 to text items of env_list --","区切りでリストにする
    
    set AppleScript's text item delimiters to OriginalDelimiters
    --もともとの区切り文字に戻しておく。これも決まり事。
    
  • リストから選択
    set mySelect to choose from list value2

  • ダイアログ表示
    display dialog "Done"

  • リストの1つ目を変数に入れる(indexは0でなく1始まり)
    set mySelect to item 1 of mylist

  • 変数にリストを入れる
    set list_ to {"value1", "value2"}

  • 入力を要求
    http://tonbi.jp/AppleScript/Introduction/07/
    set value1 to paragraph 1 of text returned of (display dialog "入力してね!" default answer value2)

  • 文字列の中で変数を使用(変数はxとします)

    set x to "world"
    display dialog "Hello, " & x & "!!!"
    
  • クリップボードの内容を変数に
    set url__ to the clipboard

  • リストから選択してアイテム番号を返す
    http://piyocast.com/as/archives/1000

set aList to {"red", "blue", "green", "white"}
set aMes to "項目を選択してください"
set aRes to retItemFromListByItemNo(aList, aMes) of me
–> 3 (選択したアイテムの番号(1はじまり)が返る
–リストから選択してアイテム番号を返す
on retItemFromListByItemNo(aList, aMes)
  set aRes to choose from list aList with prompt aMes
  if aRes = false then return 0
  
  set aRes to contents of item 1 of aRes
  set hitNum to 1
  repeat with i in aList
    set j to contents of i
    if j is equal to aRes then
      exit repeat
    end if
    set hitNum to hitNum + 1
  end repeat
  return hitNum
end retItemFromListByItemNo
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?