LoginSignup
1
1

More than 1 year has passed since last update.

Catalina以降のIllustratorやPhotoshopなどで、ファイル名だけを選択状態にするAppleScript

Last updated at Posted at 2021-08-11

実行方法はいろいろあるのでお好きに。

Keyboard Maestroで実行する方が素直に動作します。
保存ダイアログ(シート、従来)のファイル名フィールドを選択後、SHIFTキーとカーソルキーを使って拡張子以外を選択させているので、AppleScriptのみで実行すると発火のためのキーにSHIFTが含まれている場合、モデファイキーをすぐ離さないと誤作動します。
Keyboard Maestroで実行すれば、押しているキーを無視してマクロ実行してくれるので、発火キーにSHIFT等含まれていても問題なし。

Keyboard Maestroのマクロは以下。

aaa.png

AppleScript部分のコードは以下。

tell application "System Events"
    set a to name of first application process whose frontmost is true
    tell window 1 of process a
        try
            set b to text field 1
        on error
            try
                set b to text field 1 of sheet 1
            on error
                return false
            end try
        end try
        set focused of b to true
        set c to value of b
        set d to offset in (reverse of characters of c as text) of "."
        return d
    end tell
end tell

Save to Variableで戻り値を変数に格納し、以降のマクロで使っています。
※捨て変数としてVariableという名前のものを使っているのでややこしいけど…

AppleScriptのみで実行する場合は以下。

tell application "System Events"
    set a to name of first application process whose frontmost is true
    tell window 1 of process a
        try
            set b to text field 1
        on error
            try
                set b to text field 1 of sheet 1
            on error
                return false
            end try
        end try
        set focused of b to true
        set c to value of b
        set d to offset in (reverse of characters of c as text) of "."
        key code 125
        repeat d times
            key code 123
        end repeat
        delay 0.1
        key code 126 using {shift down}
        return d
    end tell
end tell
1
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
1
1