2013-11-23 72 views
1

我試圖使腳本有:複製當前選擇和URL並粘貼到Excel?

  1. 複製當前選擇和網址在Safari
  2. 貼在選擇小區1
  3. 在小區2
  4. 粘貼URL
  5. 轉到下面的小區1新行在Excel中

怎麼可以這樣使用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

爲什麼你需要這到底是什麼?將URL寫入製表符分隔的文本文件是否足以將其導入到Excel中?你有沒有你自己試過的代碼? (當你在這裏發帖時,你應該至少對編碼有最少的瞭解)。 – Mark

+0

我需要使用源URL保存一些引號,但我無法在Excel中的單元格之間導航。 – vantage5353

+0

請回答我的問題,如果你想得到任何幫助。 – Mark

回答

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 
+0

看看我原來的帖子,看看我是如何使用你的代碼。我需要在操作結束時將活動單元格設置爲下一行的第一個單元格,以便不覆蓋先前的條目。我嘗試將活動單元格設置爲_,但它似乎不起作用。想法? – vantage5353

+0

@ user1891836:我的解決方案避免使用活動單元格通過尋找在A列的第一個空單元格它做你問什麼,每一個腳本,而不會覆蓋任何數據運行時間開始的新行。給它一個去看看它的行動。 – adamh

+0

它的工作原理應該如此。我只是想知道爲什麼沒有辦法移動當前的選擇(即活動單元格)... – vantage5353