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 3 years have passed since last update.

デスクトップアイコン位置を保存・元に戻すKeyboardMaestroマクロ

Posted at

Finderアイコン表示とリスト表示で、Cmd+プラスマイナスを押すとアイコンサイズが変えられます。

…ところがDesktopを選択した状態でこのキーボードショートカットを押すと、デスクトップに置いたボリューム、フォルダなどのアイコン類が配置されなおされてしまうのですよね…
Preview.app等でCmd+プラスしているとき、うっかりデスクトップがアクティブな状態でキーを押してしまうと、きれいに配置したアイコンがあああ、ということに。

なのでこれを元に戻すマクロを作りました。

現在の位置を保存する

225661559580.png

AppleScript部は↓

tell application "Finder"
	set myItems to {}
	set a to every item of desktop
	repeat with i in a
		set idp to desktop position of i
		set dp to item 1 of idp & "," & item 2 of idp
		set nm to name of i as text
		set nk to kind of i as text
		if nk is "ボリューム" or nk is "フォルダ" then set end of myItems to nm & "," & nk & "," & dp & return
	end repeat
	return myItems as text
end tell

ファイルの書き出しや(後でやる)読み込みは、AppleScriptのみで行うとお片付けミスのコストがきついので、Keyboard Maestroに全て任せます。

書き出したファイルはボリューム名、種類(あまり意味なさげ)、デスクトップのxy+改行のcsvファイルになります。

csvなので、1pxズレなどを気の済むように揃えてください。

位置を戻す

225661802837.png

csvを読み込んで、正規表現で変数に分け、AppleScriptでそれぞれ読み込んで処理します。
毎回every itemを取得して一個ずつKMで回しているので目に見えて遅いです。

AppleScript部は↓

tell application "Keyboard Maestro Engine"
	set myN to getvariable "kmN"
	set myK to getvariable "kmK"
	set myP to {getvariable "kmPx", getvariable "kmPy"}
	tell application "Finder"
		repeat with i in every item of desktop as list
			set flK to kind of i
			set flN to name of i
			if flK = myK and flN = myN then
				set i's desktop position to myP
			end if
		end repeat
	end tell
end tell
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?