String Applescript用于将桌面Gmail链接转换为iOS Gmail应用程序链接

String Applescript用于将桌面Gmail链接转换为iOS Gmail应用程序链接,string,gmail,applescript,String,Gmail,Applescript,我正在寻找建立一个Applescript,将桌面Gmail消息链接作为输入,并输出一个URL,将在iOS上工作,在iOS Gmail应用程序中打开相同的消息 下面是一个典型的Gmail URL: 以下是在iOS上运行相同URL所需的外观: 去oglegmail:///cv=143c5ddc34313e1f/accountId=2 几点注意: 重要部分(线程标识符)是原始桌面URL中字符串的最后一部分。这就是移动URL中cv=之后需要做的事情。然而,由于Gmail允许多个帐户登录,我们还需要注意

我正在寻找建立一个Applescript,将桌面Gmail消息链接作为输入,并输出一个URL,将在iOS上工作,在iOS Gmail应用程序中打开相同的消息

下面是一个典型的Gmail URL:

以下是在iOS上运行相同URL所需的外观:

去oglegmail:///cv=143c5ddc34313e1f/accountId=2

几点注意:

重要部分(线程标识符)是原始桌面URL中字符串的最后一部分。这就是移动URL中cv=之后需要做的事情。然而,由于Gmail允许多个帐户登录,我们还需要注意/u/后面的帐户ID号,桌面上的是1,而手机上的是2。看起来桌面URL从0开始编号,而移动URL从1开始编号,这取决于您首先登录的帐户。因此,我们需要将iOS URL的帐户ID号增加1

此外,我也不确定收件箱之前的“?zx=tso6hataagpp”是什么;我发现,有时候我的桌面Gmail URL包含了这一部分,而有时候不包含(但仍然包含收件箱)。我认为这并不重要,因为我们想要的重要部分在字符串的末尾,数字在始终一致的“mail.google.com/mail/u/”后面

理想情况下,Applescript会在剪贴板上查找桌面Gmail URL,如果找到了,它会输出相同的URL,然后是换行符,然后是紧跟其后的iOS URL,如下所示:

去oglegmail:///cv=143c5ddc34313e1f/accountId=2


任何Applescript大师都可以告诉我如何一起破解它吗?

尝试以下方法-通过
执行shell脚本将解析委托给bash

#从剪贴板获取文本。
#使用以下各项进行测试:https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f"
将hLink设置为(将剪贴板设置为文本)
#解析链接以提取感兴趣的信息。
将parseResult设置为执行shell脚本
“[[”&引用hLink的形式&“=~/u/([0-9]+)/。+#收件箱/(.+)$]”&&
printf“%s\\n”\“${BASH\u重新匹配[1]}\”\“${BASH\u重新匹配[2]}”
#合成Gmail for iOS链接。
将gmLink设置为“g”ooglemail:///cv=" & ¬
(parseResult第2段)和“/accountId=“&(1+(parseResult第1段))
#综合结果
将res设置为hLink&linefeed&gmLink
#将结果放回剪贴板。
将剪贴板设置为res

我能想到的最简单的方法是:

这将获得固定路径组件。i、 e构成部分5和最后一项

  --https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f

set pathUrl to (the clipboard)
set pathComponents to words of pathUrl
if item 1 of pathComponents is "https" and item 2 of pathComponents is "mail.google.com" then

    set composed to pathUrl & return & "googlegmail:///cv=" & last item of pathComponents & "/accountId=" & (((item 5 of pathComponents) as number) + 1)
end if

这确保它总是在“u”之后获得组件(帐户),而不管它在哪里。 您可以使用“收件箱”对邮件id执行相同的操作

    set composed to ""
    --set pathUrl to "https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f"
    set pathUrl to (the clipboard)
    set pathComponents to words of pathUrl
    if item 1 of pathComponents is "https" and item 2 of pathComponents is "mail.google.com" then

        repeat with i from 1 to number of items in pathComponents
            set this_item to item i of pathComponents
            if this_item is "u" then
                set this_item to item (i + 1) of pathComponents
                set composed to pathUrl & return & "googlegmail:///cv=" & last item of pathComponents & "/accountId=" & ((this_item as number) + 1)
 exit repeat
            end if
        end repeat

    end if

  composed