我想要制作的剧本必须:
如何使用AppleScript完成此操作?
我从这开始:
tell application "Safari"
set theURL to URL of front document
set theText to (do JavaScript "(''+getSelection())" in document 1)
end tell
tell application "Microsoft Excel"
set value of active cell to the theURL
end tell
但我不知道如何使用AppleScript 导航到相邻的单元格。
adamh 的代码完美地做到了这一点:
tell application "Safari"
set theURL to URL of front document
set theText to (do JavaScript "(''+getSelection())" in document 1)
end tell
tell application "Microsoft Excel"
set foundRange to find range "A:A" what "" -- finds the first empty cell in column A
set the value of foundRange to theText
-- Work out its adjacent cell in same row
set cur_col to the first column index of foundRange
set cur_row to the first row index of foundRange
set nextCell to cell cur_row of column (cur_col + 1)
set value of nextCell to theURL
select cell (cur_row + 1) of column cur_col -- select the next logical cell
end tell
答案 0 :(得分:2)
根据您的上述代码提供此内容。
它的工作原理是在A列中找到插入点的第一个空单元格。
tell application "Safari"
set theURL to URL of front document
set theText to (do JavaScript "(''+getSelection())" in document 1)
end tell
tell application "Microsoft Excel"
set foundRange to find range "A:A" what "" -- finds the first empty cell in column A
set the value of foundRange to theText
-- Work out its adjacent cell in same row
set cur_col to the first column index of foundRange
set cur_row to the first row index of foundRange
set nextCell to cell cur_row of column (cur_col + 1)
set value of nextCell to theURL
select cell (cur_row + 1) of column cur_col -- select the next logical cell
end tell