2011-01-25 27 views
0

我的意思是,如果我有这在我的剪贴板例如:Applescript解析flickr网址?更改大小,并添加页面链接

“http://farm6.static.flickr.com/5290/5377008438_8e3658d75f_m.jpg”

我可以使用AppleScript的更改到

“http://farm6.static.flickr.com/5290/5377008438_8e3658d75f_b.jpg”

(改变 “M” 到 “b”) ?

这会很方便,因为那样我就可以从缩略图页面右键单击/复制照片url而无需向下钻取。是的,从缩略图页面到大尺寸只需点击几下鼠标,但我可以保存的任何内容都不错。

此外,我可以复制照片ID,以便我可以链接到主照片页面?

例如:

副本“5377008438”,并粘贴到一个主链接“http://www.flickr.com/photos/dbooster/5377008438”

我只能说AppleScript的,因为这涉及到介意,但我可以从文本扩展器调用的任何东西都可以工作。

+0

解析URL是不是一个问题,有很多方法可以做这样的事情,但你想在解析URL做什么你在这里失踪把它放回剪贴板或把它放在一个文本文件,我们不知道接下来会发生什么 – mcgrailm 2011-01-25 14:10:18

回答

0

我想这应该是你的出发点:

changeUrl("http://farm6.static.flickr.com/5290/5377008438_8e3658d75f_m.jpg") 

on changeUrl(theUrl) 
    set theNewUrl to do shell script "echo " & theUrl & "| tr '_m.jpg' '_b.jpg' " 
end changeUrl 

...虽然我可不是完全确定,什么you're试图在年底前实现 - 你想生成结尾的链接从“5377008438”的“_b.jpg”中从剪贴板中读取?

1

操纵URL可以这样做:

set baseURL to "http://farm6.static.flickr.com/5290/5377008438_8e3658d75f_m.jpg" 

set modURL to (characters 1 through -6 of baseURL as text) & "b.jpg" 

set fileName to last item of (tokens of baseURL between "/") 
set photoID to first item of (tokens of fileName between "_") 
set mainPhotoPage to "http://www.flickr.com/photos/dbooster/" & photoID 

{modURL, fileName, photoID, mainPhotoPage} 

on tokens of str between delimiters 
    set oldTIDs to text item delimiters of AppleScript 
    set text item delimiters of AppleScript to delimiters 
    set strtoks to text items of str 
    set text item delimiters of AppleScript to oldTIDs 
    return strtoks 
end tokens 

当我运行该脚本,我得到

{"http://farm6.static.flickr.com/5290/5377008438_8e3658d75f_b.jpg", "5377008438_8e3658d75f_m.jpg", "5377008438", "http://www.flickr.com/photos/dbooster/5377008438"} 

我真不明白你是否需要与剪贴板交互帮助。但它很容易在任何情况下,你可以使用getset

get the clipboard 
set the clipboard to "example" 
0

感谢您的答复大家!

对于不给出更多细节,我表示歉意。今天早上我使用了Michael给出的代码,修改它以拍摄两个变量(直接的照片网址和照片标题),并吐出一些用于显示照片和链接的降价代码的参考结束,提示我输入照片尺寸和边框。

它似乎工作得很好。这是我写的。

copy (the clipboard) to URL_TITLE 

set baseURL to first text item of (tokens of URL_TITLE between " ") 
set baseTitle to ("\"" & second text item of (tokens of URL_TITLE between "\"") & "\"") 

set modURL to (characters 1 through -6 of baseURL as text) & "b.jpg" 

set fileName to last item of (tokens of baseURL between "/") 
set photoID to first item of (tokens of fileName between "_") 
set mainPhotoPage to "http://www.flickr.com/photos/dbooster/" & photoID 

set photoWidth to the text returned of (display dialog "Photo Width?" default answer "980") 
set photoHeight to the text returned of (display dialog "Photo Height?" default answer "605") 
set photoBorder to the text returned of (display dialog "Border Size?" default answer "10") 

set var6 to ("[photo]: " & modURL & " " & baseTitle & " width=" & photoWidth & "px" & " height=" & photoHeight & "px" & " style=\"border: " & photoBorder & "px solid black\" class=\"aligncenter shadow\" & "\n" & [photopage]: " & mainPhotoPage & " target=\"_blank\" rel=\"nofollow\"") 

set the clipboard to var6 

on tokens of str between delimiters 
    set oldTIDs to text item delimiters of AppleScript 
    set text item delimiters of AppleScript to delimiters 
    set strtoks to text items of str 
    set text item delimiters of AppleScript to oldTIDs 
    return strtoks 
end tokens 

就像我说的,所有的作品都很棒。我有一个Firefox插件,将直接照片链接和照片标题(URL“TITLE”)复制到剪贴板中。然后,我用Fastscripts为这个脚本分配一个热键,并将结果返回到剪贴板。然后我可以将结果粘贴到我的发布模板文件中。

我无法得到它与文本扩展工作,但Fastscripts调用它的速度不够快,所以没有问题。

说实话......我很少知道我做到了。我根本不知道AppleScript。我只是提出了我的问题,因为文本扩展器支持它,它似乎很容易。所以即使我写的脚本似乎也能工作,除了我摆弄迈克尔给出的代码外,没什么。

所以这是说,如果你看到一个更有效的方式做我做什么,我洗耳恭听。再次帮助

谢谢,伙计们!

+0

我不认为你会找到什么有效得多。它太慢了吗? – 2011-01-26 16:12:53