Alfred+qshell

Alfred+qshell

在用macDown写文档时,有时候需要粘贴一些图片,这时要用到第三方的存储平台来存储图片,然后给出图片的外链,在macDown中引用此外链即可。
这个流程是比较繁琐的,可以使用Alfred+qshell来自动化此流程。可以参考https://www.zybuluo.com/fyywy520/note/317999

Alfred

去google

qshell

https://developer.qiniu.com/kodo/tools/1302/qshell,上面那篇文章中用的是qrsync工具,但是这个工具已经废弃了,不建议用。

代码

这里的代码只是改变了上述那篇文章提及的代码中工具的使用,其他都是一样的。

property fileTypes : {¬
    {«class PNGf», ".png"}, ¬
    {JPEG picture, ".jpg"}}
on getType()
    repeat with aType in fileTypes
        repeat with theInfo in (clipboard info)
            if (first item of theInfo) is equal to (first item of aType) then return aType
        end repeat
    end repeat
    return missing value
end getType
set theType to getType()
if theType is not missing value then
    set filePath to "/Users/jam/study/qiniu/picture/" --这里换成你自己放置图片的路径
    set fileName to do shell script "date \"+%Y%m%d%H%M%S\" | md5" --用当前时间的md5值做文件名
    if fileName does not end with (second item of theType) then set fileName to (fileName & second item of theType as text)
    set markdownUrl to "![](http://7xis01.com1.z0.glb.clouddn.com/macdown-" & fileName & "-960.jpg)" --这里是你的七牛域名和设置的图片样式
    set filePath to filePath & fileName
    try
        set imageFile to (open for access filePath with write permission)
        set eof imageFile to 0
        write (the clipboard as (first item of theType)) to imageFile
        close access imageFile
        set the clipboard to markdownUrl
        try
            tell application "System Events"
                keystroke "v" using command down
            end tell
        end try
        do shell script "/Users/jam/study/qiniu/qshell qupload /Users/jam/study/qiniu/conf.json" 
    on error
        try
            close access imageFile
        end try
        return ""
    end try
else
    return ""
end if
  • 从代码可以看出,qshell使用的配置也是json格式的。我的配置如下:
{
  "src_dir":"/Users/jam/study/qiniu/picture",
  "bucket":"jams",
  "rescan_local":true,
  "key_prefix":"macdown-",
  "check_exists":true,
  "check_hash":true,
  "check_size":true
}
  • 根据自己的环境进行更改即可。

猜你喜欢

转载自blog.csdn.net/ljm_csdn/article/details/79853748