Skip to content

Instantly share code, notes, and snippets.

@tgck
tgck / getFilteredItemsPosition.py
Last active August 29, 2015 14:20
[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)
@tgck
tgck / playSounds.py
Created May 5, 2015 19:27
[python][sound] ファイルリスト取得 -パターンマッチ- 再生 (afplay)
import os
import fnmatch
workdir = "/Users/tani/Desktop"
exts = ["*.aif", "*.wav", "*.m4a"]
resultlist = []
for pattern in exts :
resultlist.extend( fnmatch.filter(os.listdir(workdir), pattern) )
@tgck
tgck / getMousePosition.py
Created May 4, 2015 14:31
[Python][Quartz] マウス座標を取得する
import Quartz
q = Quartz
e = q.CGEventCreate(None) # CGEventRef を得る
p = q.CGEventGetLocation(e) # CGPoint を得る
q.CFRelease(e)
print p.x, p.y
# 参考
http://stackoverflow.com/questions/21396985/how-to-use-cgeventcreatekeyboardevent-in-python-on-mac
@tgck
tgck / checkCoodinates.sh
Last active August 29, 2015 14:20
[bash][objective-c] マウス操作における座標の確認(NS/CG)
# https://discussionsjapan.apple.com/thread/10156340
# chandana さんの回答
# ちょっとしたプログラムを
#!/bin/bash
TEMPDIR="$(mktemp -d ~/desktop/temp_XXXX)" && cd "$TEMPDIR" || exit
cat <<'EOF' > main.m
#import <Foundation/Foundation.h>
@tgck
tgck / replace.py
Created May 2, 2015 17:35
[python] 文字列の置換(パターンマッチングによる抽出 + 単純置換)
# この文字列の'file://'を除去したい
>>> str = u'file:///Users/tani/Desktop/20150404_ome_compressed_tani1.zip'
>>> import re
>>> matched = re.search('//.*', str) # strの部分一致を返す
# マッチ結果
>>> matched.group()
u'///Users/tani/Desktop/20150404_ome_compressed_tani1.zip'
>>>
@tgck
tgck / conversionOfNSURLandNSString.py
Last active August 29, 2015 14:20
[python][ScriptingBridge] NSURLとNSStringの相互変換
# NSURLクラスのメソッド使って文字列をNSURLオブジェクトに変換する
>>> zzz = Foundation.NSURL.fileURLWithPath_("/Users/tani/Desktop/20150404_ome_compressed_tani1.zip")
>>> zzz
file:///Users/tani/Desktop/20150404_ome_compressed_tani1.zip
# NSURLオブジェクトから文字列(POSIX path)の取り出し
>>> zzz.path()
@tgck
tgck / getItemNameAndNameExtension.py
Created May 2, 2015 16:33
[python][scriptingBridge][メモ] Finder項目の名前と拡張子を取得する
>>> for i in a2:
... print i.name(), i.nameExtension()
...
20150404_ome_compressed_tani1.zip zip
20150404_ome_compressed_tani2.zip zip
IMG_1583.JPG JPG
Untitled2.mp4 mp4
Untitled2_org.mp4 mp4
Untitled2trimmed.mov mov
UntitledRibbon2.mp4 mp4
@tgck
tgck / getFilesAndFolders.py
Last active February 13, 2016 12:40
[ruby][python][ScriptingBridge] finderの子要素をリストで取得してみる
# /usr/bin/python
# -*- coding: utf-8 -*-
# システム標準のpythonを使用する(OSX 10.6)
from ScriptingBridge import *
from Foundation import *
finder = SBApplication.applicationWithBundleIdentifier_("com.apple.finder")
files = finder.files()
# >>> files
@tgck
tgck / getDefinedNamesOfObject.py
Last active August 29, 2015 14:20
[python][ScriptingBridge] オブジェクトに定義されたメソッドを調べる
#
from ScriptingBridge import *
from Foundation import *
finder = SBApplication.applicationWithBundleIdentifier_("com.apple.finder")
#
# その1
#
methodlist = dir(finder) # 組込関数でメソッドを列挙
@tgck
tgck / ScriptingBridgeSample.py
Created May 2, 2015 11:38
[ScriptingBridge]Finderのうち、ディレクトリを取得してデスクトップ座標も取得
# システム標準のpythonをつかうこと
# /usr/bin/python
# -*- coding: utf-8 -*-
from ScriptingBridge import *
from Foundation import *
finder = SBApplication.applicationWithBundleIdentifier_("com.apple.finder")
folders = finder.desktop().folders()
for i in folders :
print i.name(), i.desktopPosition()