본문

웨일 북마크 워크플로우 개발 - 3


도입

이번 포스팅에서 기능 구현 및 TroubleShooting에 대해 정리할 예정이다.


구현

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Step1. Set my profile path
WhaleBookMarkPath = os.path.expanduser('~/Library/Application Support/Naver/Whale/Profile 1/bookmarks')
 
Bookmark = namedtuple('Bookmark''name url')
 
bookMarkList = []
def searchItem(targetJson):
    if('children' in targetJson):
        searchItem(targetJson['children'])
    else:
        for item in targetJson:
            if ('children' in item):
                searchItem(item['children'])
            else:
                bookMarkList.append(UrlItem(item['name'],item['url']))
 
# Skip Parser ...
 
def main():
   # Step2. Parse data from the json file
   Parser.parseForJson(WhaleBookMarkPath)
   json.dump(dict(items=mapToAlfredJson()), sys.stdout, indent=2, sort_keys=True, cls=EnhancedJSONEncoder)
   return 0
 
def mapToAlfredJson():
    alfredJsonList = []
    # Step3. Create data for alfred
    for item in bookMarkList:
        alfredJsonList.append(dict(
            title=item.name,
            subtitle=item.url,
            arg=item.url,
            uid=item.url,
            valid=True,
        ))
    return alfredJsonList
 
if __name__ == "__main__":
    code = main()
    sys.exit(code)
 
cs

TroubleShooting

모르는 내용들은 ‘Alfred forum’에 문의했고 아래 내용은 문의 내용을 정리한 것이다.

 

[SOLVED] Pass the result to Alfred by Script Filter

Hello, I’m developing bookmark workflow for the minor browser. Now, I faced the problem. I’m pass Alfred Json by script filter. When I run my code by `python3`, I checked correct outputs like below: { items: [ { arg: https://www.alfredapp.com/help/workflow

www.alfredforum.com

1. shebang

alfred에서 스크립트를 실행할 명령어를 선택할 수 있다. 나는 처음에 python3로 했고 python3로 실행 시키려고 했다. 그러나 python3는 default로 지원하지 않아 ‘/usr/bin/python’에 링크를 통해 ptyhon3를 실행하려고 시도했다.
그러나 python에 python3를 링크할 수 없다는 것을 알게되었다. 확인해보니 ‘shebang’을 통해 원하는 명령어를 실행할 수 있다는 것을 알게되었다.

2. python2 VS python3

shebang으로 python3로 실행하는 것은 문제 해결!

python3를 사용했던 이유는 ‘dataclass’ 때문이다. python2에도 유사한 namedTuble이 존재하지만 dataclass가 익숙했고 python3에서 지원하고 있어 사용했다.
그러나, python3 mac OS에 default로 설치된 명령어가 아니다. 그러므로 환경에 따라 스크립트를 싱행하지 못할 수 있다.

default로 설치된 python2 사용!


스크린 샷


Github Repo

 

Heepie/WhaleBookmark-workflow

This is Alfred Workflow for searching the 'Whale' browser's bookmark - Heepie/WhaleBookmark-workflow

github.com

 

 

#웨일 #북마크 #알프레드 #워크플로우 #alfred #workflow

'컴퓨터 > Mac' 카테고리의 다른 글

웨일 북마크 워크플로우 개발 - 2  (0) 2020.02.18
웨일 북마크 워크플로우 개발 - 1  (0) 2020.02.17
Alfred 접근 권한 설정  (0) 2020.02.16

공유

댓글