This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# この文字列の'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' | |
>>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
from ScriptingBridge import * | |
from Foundation import * | |
finder = SBApplication.applicationWithBundleIdentifier_("com.apple.finder") | |
# | |
# その1 | |
# | |
methodlist = dir(finder) # 組込関数でメソッドを列挙 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# システム標準の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() |