Applescript 解析 flickr url?更改大小并添加页面链接

发布于 2024-10-13 23:45:31 字数 502 浏览 3 评论 0原文

我的意思是,如果我的剪贴板中有这个:

“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,因为我想到了这一点,但我可以从文本扩展器调用的任何内容都会工作。

What I mean, is if I have this in my clipboard for instance:

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

can I use applescript to change that to

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

(changing the "m" to a "b")
?

This would be handy because then I could just right click/copy the photo url from the thumbnails page without having to drill down. Yes, it's only a few clicks to get from the thumbnails page to the large size, but any I can save would be nice.

Also, could I copy out the photo id so that I can link to the main photo page?

ex:

copy the "5377008438" and paste into a main link "http://www.flickr.com/photos/dbooster/5377008438"

I only say applescript because that comes to mind, but anything that I could call from text expander would work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无妨# 2024-10-20 23:45:31

谢谢大家的回复!

我很抱歉没有提供更多细节。今天早上,我使用了 Michael 提供的代码,将其修改为采用两个变量(直接照片 URL 和照片标题),并吐出一些用于显示照片和链接的 Markdown 代码的参考端,提示我输入照片尺寸和边框。

看起来效果很好。这是我写的。

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。我只是建议它来解决我的问题,因为文本扩展器支持它并且它看起来很简单。因此,即使我写的脚本似乎有效,但这只是我摆弄迈克尔给出的代码。

所以这就是说,如果您发现一种更有效的方法来完成我所做的事情,我洗耳恭听。

再次感谢你们的帮助,伙计们!

Thanks for the replies everyone!

I apologize for not giving more details. This morning I used the code Michael gives, modifying it to take two vars (the direct photo url and the photo title) and spit out the reference end of some markdown code for displaying the photo and link, prompting me for photo dimensions and border.

It seems to work pretty well. Here is what I wrote.

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

Like I said, all works great. I have a firefox plugin that copies the direct photo link and photo title (URL "TITLE") into the clipboard. I then assigned this script a hotkey with Fastscripts and it returns the result to the clipboard. Then I can paste the result to my post template file.

I couldn't get it to work with text expander, but Fastscripts calls it quickly enough so there is no problem.

To be honest... I have very little idea what I did. I don't know AppleScript at all. I only suggested it for my question because text expander supports it and it seemed easy enough. So even tho the script I wrote seems to work, it is nothing but me fiddling around with the code Michael gave.

So this is to say, if you see a much more efficient way to do what I did, I am all ears.

Thanks again for the help, guys!

吹梦到西洲 2024-10-20 23:45:31

我认为这应该是你的起点:

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

......虽然我不太确定,你最终想要实现什么 - 你想从“5377008438”生成一个以“_b.jpg”结尾的链接吗从剪贴板中读取?

I think this should be your starting point:

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

...though I´m not exactly sure, what you´re trying to achieve in the end - do you want to generate a link ending in "_b.jpg" from "5377008438" being read from your clipboard?

豆芽 2024-10-20 23:45:31

操作 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"

Manipulating the URL can be done like this:

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

When I run that script, I get

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

I'm not really clear whether you need help with interacting with the clipboard. But it's easy at any rate, you can just use get and set:

get the clipboard
set the clipboard to "example"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文