# [メタ情報] # 識別子: マイライブラリ_画面入力_exe # システム名: マイライブラリ_画面入力 # 技術種別: Misc # 機能名: Misc # 使用言語: AppleScript Python # 状態: 実行用 # [/メタ情報] ▫️画面入出力 Dropboxからライブラリ作成 AppleScript ◆M1 Mac用 on run {input, parameters} -- 入力がない場合のエラー処理 if input is {} then display alert "ファイルまたはフォルダが選択されていません。" message "Finderで処理したいファイルを選択してください。" return end if -- ファイル情報の取得 set filePath to POSIX path of item 1 of input if filePath contains "/Users/xxxxxxxx/" then set filePath to do shell script "echo " & quoted form of filePath & " | sed 's#^/Users/xxxxxxxx/#/Volumes/NO3_SSD/#'" end if set fileName to (do shell script "basename " & quoted form of filePath) set extn to do shell script "echo " & quoted form of fileName & " | sed -E 's/.*\\.(.*)$/\\1/'" -- 日本語などを除去してDropboxのファイル名形式に近づける set cutjp_fileName to do shell script " echo " & quoted form of fileName & " | sed -E ' s/[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9ア-ン゙゚]+/-/g; s/-([.][^.]+)$/\\1/; s/^-+(.*)$/\\1/; s/--+/-/g' " -- Python(仮想環境)でDropboxリンクを取得 set pythonPath to "/Users/xxxxxxxxm1/venv_dropbox/bin/python" set getLinkScript to "/Users/xxxxxxxxm1/python_scripts/get_dropbox_link.py" set dropboxLink to do shell script pythonPath & " " & quoted form of getLinkScript & " " & quoted form of filePath -- 整合性チェック:Dropboxリンクにcutjp_fileNameが含まれているか if dropboxLink does not contain cutjp_fileName then display dialog "Dropboxリンクと選択したファイルの名前が一致しない可能性があります。 推定ファイル名: " & cutjp_fileName & return & "このまま続行しますか?" buttons {"キャンセル", "続行"} default button "キャンセル" if button returned of result is "キャンセル" then return end if -- Python(仮想環境)で送信スクリプトを実行 set sendScript to "/Users/xxxxxxxxm1/python_scripts/send_request.py" set cmd to pythonPath & " " & quoted form of sendScript & " " & quoted form of dropboxLink & " " & quoted form of filePath & " " & quoted form of fileName & " " & quoted form of extn set response to do shell script cmd -- 結果を表示 display dialog response end run ◆M2 Mac用 -- ◆M2 Mac用 AppleScript(Dropboxリンクを自動取得するバージョン) on run {input, parameters} -- 入力がない場合のエラー処理 if input is {} then display alert "ファイルまたはフォルダが選択されていません。" message "Finderで処理したいファイルを選択してください。" return end if -- ファイル情報の取得 set filePath to POSIX path of item 1 of input if filePath contains "/Users/xxxxxxxx/" then set filePath to do shell script "echo " & quoted form of filePath & " | sed 's#^/Users/xxxxxxxx/#/Volumes/NO3_SSD/#'" end if set fileName to (do shell script "basename " & quoted form of filePath) set extn to do shell script "echo " & quoted form of fileName & " | sed -E 's/.*\\.(.*)$/\\1/'" -- 日本語などを除去してDropboxのファイル名形式に近づける set cutjp_fileName to do shell script " echo " & quoted form of fileName & " | sed -E ' s/[一-龠ぁ-ゔァ-ヴーa-zA-Z0-9ア-ン゙゚]+/-/g; s/-([.][^.]+)$/\\1/; s/^-+(.*)$/\\1/; s/--+/-/g' " -- DropboxリンクをPython経由で取得(クリップボードは使用しない) set pythonScriptPath to "/Users/xxxxxxxx/python_scripts/get_dropbox_link.py" set pythonPath to "/Users/xxxxxxxx/venv_dropbox/bin/python" set dropboxLink to do shell script pythonPath & " " & quoted form of pythonScriptPath & " " & quoted form of filePath -- 整合性チェック:Dropboxリンクにcutjp_fileNameが含まれているか if dropboxLink does not contain cutjp_fileName then display dialog "Dropboxリンクと選択したファイルの名前が一致しない可能性があります。 推定ファイル名: " & cutjp_fileName & return & "このまま続行しますか?" buttons {"キャンセル", "続行"} default button "キャンセル" if button returned of result is "キャンセル" then return end if -- Python スクリプトの実行(send_request.py) set sendRequestPath to "/Users/xxxxxxxx/python_scripts/send_request.py" set cmd to pythonPath & " " & quoted form of sendRequestPath & " " & quoted form of dropboxLink & " " & quoted form of filePath & " " & quoted form of fileName & " " & quoted form of extn set response to do shell script cmd -- Python からのレスポンスを表示 display dialog response end run