Skip to content

Instantly share code, notes, and snippets.

@mk2
Last active August 29, 2015 13:58
Show Gist options
  • Save mk2/9952042 to your computer and use it in GitHub Desktop.
Save mk2/9952042 to your computer and use it in GitHub Desktop.
Enable Annotations on AppleScript
(*
AppleScriptでJavaのアノテーションのようなことをやるスクリプト。
# 使い方
コピペして~/Library/Script Libraries/以下にAnnotationContainer.scptとして保存(保存時にコンパイルしておくこと)
後は使いたい場所で
use AnnotationContainer : script "AnnotationContainer"
すれば使えます。
AnnotationContainerのメソッド
(1) アノテーションの追加
- (void)putKey:(text)aKey value:(id)values
(2) アノテーションの取得
- (void)getKey:(text)aKey
*)
to annotationContainerFactory:anAnnotations
-- スクリプトオブジェクト
script AnnotationContainer
property annotations : anAnnotations
-- アノテーション追加
to putKey:aKey value:aValue
log "KEY[" & aKey & "] VALUE[" & aValue & "]"
copy {|key|:aKey, value:aValue} to the end of my annotations
end putKey:value:
-- 引数のキーに対応したアノテーションの値を取得
to getKey:aKey
set values to {}
repeat with anno in my annotations
if aKey is equal to |key| of anno then
copy value of anno to the end of values
end if
end repeat
return values
end getKey:
end script
end annotationContainerFactory:
to new:textContent
set annotations to {}
set stateInLineComment to false
set stateInBlockComment to false
repeat with p in every paragraph of textContent
if p contains "--" then
set stateInLineComment to true
end if
if p contains "(*" then
set stateInBlockComment to true
end if
if p contains "*)" then
set stateInBlockComment to false
end if
if (stateInLineComment or stateInBlockComment) and p contains "@" then
set theWords to every word of p
set theKey to the first item of theWords
set theValues to the rest of theWords
copy {|key|:theKey, value:theValues} to the end of annotations
end if
set stateInLineComment to false
end repeat
return (my annotationContainerFactory:annotations)
end new:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment