Skip to content

Instantly share code, notes, and snippets.

@tgck
Last active August 29, 2015 14:20
Show Gist options
  • Save tgck/59ab0c91a23bb669b7a9 to your computer and use it in GitHub Desktop.
Save tgck/59ab0c91a23bb669b7a9 to your computer and use it in GitHub Desktop.
[python][ScriptingBridge] 特定拡張子ファイル&フォルダのリストを、座標付きで出力する
#!/usr/bin/python
from ScriptingBridge import *
import fnmatch, os
# vars. depends on your environments and goal.
WORK_DIR = "/Users/tani/Desktop"
EXTS = ["*.aif", "*.wav", "*.m4a"]
# 1. FinderItem 座標リストを作成する(ScriptingBridge)
finder = SBApplication.applicationWithBundleIdentifier_("com.apple.finder")
# collな複数フォールドリストを、tissue_boxに格納
def tissue_box():
a = finder.items()
for i in a:
p = i.desktopPosition()
yield [i.name(), int(p.x), int(p.y)]
# 出力結果サンプル
# for i in tissue_box():
# print i[0], i[1], i[2]
# ->
# MacintoshSSD 1233 42
# 01ItsNoGamePart1.m4a.aiff.aif 381 426
# 04AshesToAshes.aif 381 458
# 04AshesToAshes.m4a 381 42
# 320x320_5.gif 97 42
# 2.
# koko de extension match shita file list wo tuskuru
# - ryaku -
# make a finder-item-list which has a given extension.
resultlist = []
for pattern in EXTS :
resultlist.extend( fnmatch.filter(os.listdir(WORK_DIR), pattern) )
# extends folders.
resultlist.extend([f.name() for f in finder.folders()])
for i in resultlist: # matched list
for e in tissue_box(): # every entry
if i == e[0]:
print e[0], e[1], e[2]
break
# output sample
# MacintoshSSD 1233 42
# 01ItsNoGamePart1.m4a.aiff.aif 381 426
# 04AshesToAshes.aif 381 458
# 04AshesToAshes.m4a 381 42
# timp 523 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment