fix: AppleScript POSIX path 변수 방식 + 단일 -e 실행으로 따옴표 문제 해결
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -110,27 +110,22 @@ def save_law_file(law_name: str, content: str) -> Path:
|
||||
|
||||
|
||||
def import_to_devonthink(filepath: Path, law_name: str, category: str):
|
||||
"""DEVONthink 04_Industrial Safety로 임포트"""
|
||||
script = f'''
|
||||
tell application id "DNtp"
|
||||
set targetDB to missing value
|
||||
repeat with db in databases
|
||||
if name of db is "04_Industrial safety" then
|
||||
set targetDB to db
|
||||
exit repeat
|
||||
end if
|
||||
end repeat
|
||||
|
||||
if targetDB is not missing value then
|
||||
set targetGroup to create location "/10_Legislation/Law" in targetDB
|
||||
set theRecord to import POSIX path "{filepath}" to targetGroup
|
||||
set tags of theRecord to {{"#주제/산업안전/법령", "$유형/법령", "{category}"}}
|
||||
add custom meta data "law_monitor" for "sourceChannel" to theRecord
|
||||
add custom meta data "external" for "dataOrigin" to theRecord
|
||||
add custom meta data (current date) for "lastAIProcess" to theRecord
|
||||
end if
|
||||
end tell
|
||||
'''
|
||||
"""DEVONthink 04_Industrial Safety로 임포트 — 변수 방식"""
|
||||
fp = str(filepath)
|
||||
script = f'set fp to "{fp}"\n'
|
||||
script += 'tell application id "DNtp"\n'
|
||||
script += ' repeat with db in databases\n'
|
||||
script += ' if name of db is "04_Industrial safety" then\n'
|
||||
script += ' set targetGroup to create location "/10_Legislation/Law" in db\n'
|
||||
script += ' set theRecord to import fp to targetGroup\n'
|
||||
script += f' set tags of theRecord to {{"#주제/산업안전/법령", "$유형/법령", "{category}"}}\n'
|
||||
script += ' add custom meta data "law_monitor" for "sourceChannel" to theRecord\n'
|
||||
script += ' add custom meta data "external" for "dataOrigin" to theRecord\n'
|
||||
script += ' add custom meta data (current date) for "lastAIProcess" to theRecord\n'
|
||||
script += ' exit repeat\n'
|
||||
script += ' end if\n'
|
||||
script += ' end repeat\n'
|
||||
script += 'end tell'
|
||||
try:
|
||||
run_applescript_inline(script)
|
||||
logger.info(f"DEVONthink 임포트 완료: {law_name}")
|
||||
@@ -210,28 +205,23 @@ def _should_run(last_check: dict, key: str, interval_days: int) -> bool:
|
||||
|
||||
|
||||
def _import_foreign_to_devonthink(filepath: Path, title: str, country: str):
|
||||
"""외국 법령 DEVONthink 임포트 — 파일 경로만 사용 (특수문자 안전)"""
|
||||
"""외국 법령 DEVONthink 임포트 — 변수 방식 (POSIX path 따옴표 문제 회피)"""
|
||||
folder = {"US": "US", "JP": "JP", "EU": "EU"}.get(country, country)
|
||||
fp = str(filepath)
|
||||
script = (
|
||||
'tell application id "DNtp"\n'
|
||||
' set targetDB to missing value\n'
|
||||
' repeat with db in databases\n'
|
||||
' if name of db is "04_Industrial safety" then\n'
|
||||
' set targetDB to db\n'
|
||||
' exit repeat\n'
|
||||
' end if\n'
|
||||
' end repeat\n'
|
||||
' if targetDB is not missing value then\n'
|
||||
f' set targetGroup to create location "/10_Legislation/Foreign/{folder}" in targetDB\n'
|
||||
f' set theRecord to import POSIX path "{fp}" to targetGroup\n'
|
||||
' set tags of theRecord to {"#주제/산업안전/법령", "$유형/법령", "' + country + '"}\n'
|
||||
' add custom meta data "law_monitor" for "sourceChannel" to theRecord\n'
|
||||
' add custom meta data "external" for "dataOrigin" to theRecord\n'
|
||||
' add custom meta data (current date) for "lastAIProcess" to theRecord\n'
|
||||
' end if\n'
|
||||
'end tell'
|
||||
)
|
||||
script = f'set fp to "{fp}"\n'
|
||||
script += 'tell application id "DNtp"\n'
|
||||
script += ' repeat with db in databases\n'
|
||||
script += ' if name of db is "04_Industrial safety" then\n'
|
||||
script += f' set targetGroup to create location "/10_Legislation/Foreign/{folder}" in db\n'
|
||||
script += ' set theRecord to import fp to targetGroup\n'
|
||||
script += f' set tags of theRecord to {{"#주제/산업안전/법령", "$유형/법령", "{country}"}}\n'
|
||||
script += ' add custom meta data "law_monitor" for "sourceChannel" to theRecord\n'
|
||||
script += ' add custom meta data "external" for "dataOrigin" to theRecord\n'
|
||||
script += ' add custom meta data (current date) for "lastAIProcess" to theRecord\n'
|
||||
script += ' exit repeat\n'
|
||||
script += ' end if\n'
|
||||
script += ' end repeat\n'
|
||||
script += 'end tell'
|
||||
try:
|
||||
run_applescript_inline(script)
|
||||
safe_title = title[:40].replace('\n', ' ')
|
||||
|
||||
@@ -94,11 +94,8 @@ def run_applescript(script_path: str, *args) -> str:
|
||||
|
||||
|
||||
def run_applescript_inline(script: str) -> str:
|
||||
"""인라인 AppleScript 실행 — 행별 -e 분할 방식"""
|
||||
lines = script.strip().split('\n')
|
||||
cmd = ["osascript"]
|
||||
for line in lines:
|
||||
cmd.extend(["-e", line])
|
||||
"""인라인 AppleScript 실행 — 단일 -e 방식"""
|
||||
cmd = ["osascript", "-e", script]
|
||||
try:
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
||||
if result.returncode != 0:
|
||||
|
||||
Reference in New Issue
Block a user