2014-01-30 72 views
0

我期待构建一个将桌面Gmail邮件链接作为输入的Applescript,并输出一个可在iOS上工作的URL,以便在iOS中打开相同的邮件Gmail应用。Applescript将桌面Gmail链接转换为iOS Gmail应用链接

下面是一个典型的Gmail网址:

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

而且这里是相同的URL将需要看起来像在iOS工作:

googlegmail:/// CV = 143c5ddc34313e1f /帐户ID = 2

一对夫妇说明:

最重要的部分(线程标识符)是在邻串的最后部分严谨的桌面网址。这就是移动URL中cv =之后需要去做的事情。但是,由于Gmail允许多帐户登录,因此我们还需要在桌面上为/ 1的移动设备上记下账户ID号码,而移动设备上的移动设备号码为2,这看起来像是桌面URL从0开始编号,而移动网址则从1开始编号,具体取决于您首先登录哪个帐户。所以我们需要为iOS网址增加帐号ID号码1。

此外,我不确定在“#inbox”之前“?zx = tso6hataagpp”是什么。我发现有时我的桌面Gmail网址包含该部分,而其他时间则不包含(但仍包含#inbox)。我认为这不重要,因为我们想要的重要部分位于字符串的末尾,以及始终一致的“mail.google.com/mail/u/”后面的数字。

理想情况下,AppleScript的会看着剪贴板桌面Gmail的URL,如果发现一个,它会输出相同的URL,然后换行,那么iOS网址紧随其后,像这样:

https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f googlegmail:/// CV = 143c5ddc34313e1f /帐户ID = 2

任何AppleScript的大师在那里,可以告诉我怎么破解起来呢?

回答

0

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

这被固定的路径组件。即组件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 
0

请尝试以下操作 - 通过do shell script将解析委托给bash。

# Get text from clipboard. 
# Test with: "https://mail.google.com/mail/u/1/?zx=tso6hataagpp#inbox/143c5ddc34313e1f" 
set hLink to (the clipboard as text) 

# Parse the link to extract the information of interest. 
set parseResult to do shell script ¬ 
    "[[ " & quoted form of hLink & " =~ /u/([0-9]+)/.+#inbox/(.+)$ ]] && 
    printf '%s\\n' \"${BASH_REMATCH[1]}\" \"${BASH_REMATCH[2]}\"" 

# Synthesize the Gmail for iOS link. 
set gmLink to "googlemail:///cv=" & ¬ 
    (paragraph 2 of parseResult) & "/accountId=" & (1 + (paragraph 1 of parseResult)) 

# Synthesize the result 
set res to hLink & linefeed & gmLink 

# Put the result back on the clipboard. 
set the clipboard to res