Last active
February 13, 2016 16:11
-
-
Save tgck/2f4e9349c56a6fc8be6c to your computer and use it in GitHub Desktop.
[ruby][scriptingBridge] orgArray.arrayByApplyingSelector(:selector) を使って必要な情報をひっこぬく
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
a = finder.files | |
b = a.arrayByApplyingSelector(:URL) | |
# OK | |
b.each do |i| | |
puts i | |
end | |
# file:///Users/tani/Desktop/01.aif | |
# file:///Users/tani/Desktop/02.aif | |
# ... | |
# NG - b は整数ではないのでこのイテレーションは文法違反 | |
for i in b do | |
puts b[i] | |
end | |
# TypeError: can't convert OSX::NSMutableString into Integer | |
# from /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_attachments.rb:1847:in `_read_impl' | |
# from /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_attachments.rb:1165:in `[]' | |
# from (irb):120 | |
# from /System/Library/Frameworks/RubyCocoa.framework/Resources/ruby/osx/objc/oc_attachments.rb:1151:in `each' | |
# from (irb):119 |
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
a = finder.files | |
b = a.arrayByApplyingSelector(:URL) | |
>> puts NSURL.URLWithString(b[0]).path | |
/Users/tani/Desktop/01.aif | |
==> nil | |
# したがって | |
b.each do |i| | |
puts NSURL.URLWithString(i).path | |
end | |
# で、こんな感じの 文字列が取れてくる | |
# /Users/tani/Desktop/01.aif | |
# /Users/tani/Desktop/02.aif | |
# /Users/tani/Desktop/IMG_3689.JPG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment