【问题标题】:OSX: Automatically upload screenshot to imageBin and put URL in clipboardOSX:自动将屏幕截图上传到 imageBin 并将 URL 放入剪贴板
【发布时间】:2014-01-27 00:34:14
【问题描述】:

我想通过 IRC 发送我的 OSX 屏幕的部分内容,并且最不费吹灰之力。

许多应用程序已经这样做了:CloudApp、Droplr、DropBox、Jing 等

问题是它们都没有返回指向实际图像的链接。他们返回一个指向包含图像的页面的链接,主要是为了获得广告。这对 IRC 没有好处;大多数 IRC 客户端都很聪明,可以在看到图像的 URL 时显示图像,但它们不够聪明,无法从这样的框架页面中提取图像。

我想写一些东西来做这个。

Shift + Cmd + F3 让我可以用鼠标选择一个矩形,并将图像放置在我的桌面上。这可以更改为另一个文件夹:http://osxdaily.com/2011/01/26/change-the-screenshot-save-file-location-in-mac-os-x/

我想让这张图片自动上传到互联网上,并在我的剪贴板中放置一个 URL 链接。

我解决了一半的问题:以下 bash 脚本将上传一张图片并将链接放入剪贴板:

#! /bin/bash

# Imagebin Loader 
# π 27.1.2014
#
# Upload image to imagebin.org, put url to image in clipboard, make noise

filename="$1"

# http://stackoverflow.com/questions/4651437/how-to-set-a-bash-variable-equal-to-the-output-from-a-command
url_out=$(
    curl  -s \
        --form "nickname=$(hostname)" \
        --form "image=@$filename;type=$(file --brief -L --mime-type "$filename")" \
        --form "disclaimer_agree=Y" \
        --form "mode=add" \
        --form "Submit=Submit" \
    http://imagebin.org/index.php \
    -w '%{redirect_url}\n'\
    )

# e.g. http://imagebin.org/288917
echo "$url_out"

# http://mywiki.wooledge.org/BashFAQ/073
number=${url_out##*/} 

printf -v new_url "http://imagebin.org/index.php?mode=image&id=%s" $number

# e.g. http://imagebin.org/index.php?mode=image&id=288917
echo "$new_url"

#http://osxdaily.com/2007/03/05/manipulating-the-clipboard-from-the-command-line/
printf "$new_url" | pbcopy

say -v Trinoids "Fooo"

现在我该如何完成难题的另一部分:每当桌面上出现新的屏幕截图时,自动执行此脚本?

链接:https://apple.stackexchange.com/questions/118698/free-screen-grabber-for-os-x

【问题讨论】:

    标签: macos bash file-upload automation screenshot


    【解决方案1】:

    当新项目添加到文件夹时,使用 Automator 文件夹操作启动脚本。您可能希望将屏幕截图重定向到桌面以外的其他位置,否则添加到桌面的所有项目都将被上传。

    【讨论】:

    【解决方案2】:

    例如将此 plist 保存为 ~/Library/LaunchAgents/example.plist:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
      <key>Label</key>
      <string>example</string>
      <key>Program</key>
      <string>/path/to/script</string>
      <key>WatchPaths</key>
      <array>
        <string>~/Desktop/</string>
      </array>
    </dict>
    </plist>
    

    然后运行launchctl load ~/Library/LaunchAgents/example.plist 或注销并重新登录以加载plist。要稍后将更改应用到 plist,请卸载并加载它。

    没有办法在WatchPaths 中使用通配符之类的东西,但您可以编辑脚本以跳过不是屏幕截图的文件:

    for f; do
      [[ $f = Screenshot\ *.jpg ]] || continue
      echo "$f"
    done
    

    (您还需要弄清楚如何避免为相同的图像多次运行脚本。)

    【讨论】:

    • 我怎样才能将参数传递给程序?因为我有&lt;key&gt;Program&lt;/key&gt; &lt;array&gt; &lt;string&gt;~/./imageBinUploader.sh&lt;/string&gt; &lt;/array&gt; 而我的imageBinUploader.sh 等待文件名作为参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2022-08-04
    相关资源
    最近更新 更多