Wednesday, August 23, 2017

#1 2017-04-11 04:26:26 pm

olivescript
Member
Registered: 2017-02-26
Posts: 14

Script for Creating Shortcut Link to Gmail with pre populated fields

I am trying to collect the email ofan account manager email at start so it can populate the email to a fiel.  I am not sure what  syntax would be used.  I tried this without success:  (refer lines
set jobMgr to text returned of (display dialog "Enter account manager email:" default answer "")
and
set emailAddress to jobMgr


This script is to set up job folders at the start of a project.

Thank you in advance for any help




global jobNum
global newJobFolder
set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set jobMgr to text returned of (display dialog "Enter account manager email:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
set newJobFolder to my newFold(jobNum, jobName, folderpath)


on newFold(theNumber, theName, thefolder)
    set emailAddress to jobMgr
    set emailSubject to theNumber & " -" & theName
    set bodyText to ""
    set emailLinkFileName to theNumber & " -" & theName
   
    set subNameList to {"Designs", "Documents", "Received"}
    set itemCount to count of subNameList
    set linkBody to "mailto:" & emailAddress & "?subject=" & my replace_chars(emailSubject, " ", "%20") & "&body=" & my replace_chars(bodyText, " ", "%20")
    tell application "Finder"
        set newJobFolder to (make new folder at thefolder with properties ¬
            {name:theNumber & " " & theName})
        repeat with i from 1 to itemCount
            make new folder at newJobFolder with properties ¬
                {name:jobNum & " " & item i of subNameList}
        end repeat
        duplicate file "Users:ace:Dropbox:Company:0000-1_E.xlsx" of startup disk to folder (jobNum & " Documents") of newJobFolder
        set name of the result to jobNum & " E.xlsx"
        make new internet location file to linkBody at newJobFolder with properties {name:emailLinkFileName, name extension:"mailloc"}
        -- This shouldn't be necessary, but for some reason the Finder always creates this file with the invalid file extension ".mailtoloc" instead of ".mailoc", even when using the explicit extension declaration. So I'm just changing the extension after making it so it will work.
        set the name extension of file (((newJobFolder as text) & emailLinkFileName) & ".mailtoloc" as alias) to "mailloc"
    end tell
end newFold

-- Generic find and replace functionality
on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars

Offline

 

#2 2017-04-12 09:40:20 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 199

Re: Script for Creating Shortcut Link to Gmail with pre populated fields

olivescript,

If you want help here, please take a moment to familiarize yourself with the forum guidelines.

http://macscripter.net/viewtopic.php?id=14134

Please post your code using the "Applescript" button above the text field where you're composing your question.

Also, this question should have been kept in the original thread:

http://macscripter.net/viewtopic.php?id=45621

If you haven't received a response it a while, you can try adding another comment in that thread and it will bump it to the top of the list, but you don't want different threads for the same script.

You collected the email address at the top level of the script, but you didn't pass the variable to the function newFold with your other variables.

Applescript:

global jobNum
global newJobFolder
set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set jobMgr to text returned of (display dialog "Enter account manager email:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
set newJobFolder to my newFold(jobNum, jobName, folderpath, jobMgr)


on newFold(theNumber, theName, thefolder, jobMgr)
   set emailAddress to jobMgr
   set emailSubject to theNumber & " -" & theName
   set bodyText to ""
   set emailLinkFileName to theNumber & " -" & theName
   
   set subNameList to {"Designs", "Documents", "Received"}
   set itemCount to count of subNameList
   set linkBody to "mailto:" & emailAddress & "?subject=" & my replace_chars(emailSubject, " ", "%20") & "&body=" & my replace_chars(bodyText, " ", "%20")
   tell application "Finder"
       set newJobFolder to (make new folder at thefolder with properties ¬
           {name:theNumber & " " & theName})
       repeat with i from 1 to itemCount
           make new folder at newJobFolder with properties ¬
               {name:jobNum & " " & item i of subNameList}
       end repeat
       duplicate file "Users:ace:Dropbox:Company:0000-1_E.xlsx" of startup disk to folder (jobNum & " Documents") of newJobFolder
       set name of the result to jobNum & " E.xlsx"
       make new internet location file to linkBody at newJobFolder with properties {name:emailLinkFileName, name extension:"mailloc"}
       -- This shouldn't be necessary, but for some reason the Finder always creates this file with the invalid file extension ".mailtoloc" instead of ".mailoc", even when using the explicit extension declaration. So I'm just changing the extension after making it so it will work.
       set the name extension of file (((newJobFolder as text) & emailLinkFileName) & ".mailtoloc" as alias) to "mailloc"
   end tell
end newFold

-- Generic find and replace functionality
on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#3 2017-04-12 10:40:41 am

olivescript
Member
Registered: 2017-02-26
Posts: 14

Re: Script for Creating Shortcut Link to Gmail with pre populated fields

thank you for your help  and reference to the forum protocol.

Offline

 

#4 2017-04-12 06:55:35 pm

olivescript
Member
Registered: 2017-02-26
Posts: 14

Re: Script for Creating Shortcut Link to Gmail with pre populated fields

One last question,  in the above script how would I make it copy the email shortcut created also into each of the three sub folders created?

Offline

 

#5 2017-04-13 08:37:35 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 199

Re: Script for Creating Shortcut Link to Gmail with pre populated fields

Applescript:

global jobNum
global newJobFolder
set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set jobMgr to text returned of (display dialog "Enter account manager email:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
set newJobFolder to my newFold(jobNum, jobName, folderpath, jobMgr)


on newFold(theNumber, theName, thefolder, jobMgr)
   set emailAddress to jobMgr
   set emailSubject to theNumber & " -" & theName
   set bodyText to ""
   set emailLinkFileName to theNumber & " -" & theName
   
   set subNameList to {"Designs", "Documents", "Received"}
   set itemCount to count of subNameList
   set linkBody to "mailto:" & emailAddress & "?subject=" & my replace_chars(emailSubject, " ", "%20") & "&body=" & my replace_chars(bodyText, " ", "%20")
   tell application "Finder"
       set newJobFolder to (make new folder at thefolder with properties ¬
           {name:theNumber & " " & theName})
       repeat with i from 1 to itemCount
           set aSubFolder to make new folder at newJobFolder with properties {name:jobNum & " " & item i of subNameList}
           set theMailto to make new internet location file to linkBody at aSubFolder with properties {name:emailLinkFileName, name extension:"mailloc"}
           set the name extension of theMailto to "mailloc"
       end repeat
       duplicate file "Users:ace:Dropbox:Company:0000-1_E.xlsx" of startup disk to folder (jobNum & " Documents") of newJobFolder
       set name of the result to jobNum & " E.xlsx"
       set theMailto to make new internet location file to linkBody at newJobFolder with properties {name:emailLinkFileName, name extension:"mailloc"}
       set the name extension of theMailto to "mailloc"
   end tell
end newFold

-- Generic find and replace functionality
on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#6 2017-04-13 09:24:16 pm

olivescript
Member
Registered: 2017-02-26
Posts: 14

Re: Script for Creating Shortcut Link to Gmail with pre populated fields

Awesome   thank you so much.  Do you know if from here it is possible to write those values into a google sheet and have it append each time to the end?

Offline

 

#7 2017-04-14 11:20:47 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 199

Re: Script for Creating Shortcut Link to Gmail with pre populated fields

It's possible, but dealing with Google Sheets must be done through the API, which is a non-trivial programming exercise.

https://developers.google.com/sheets/api/

It would be great if some guru with extra time on their hands writes an Applescript library for interfacing with Google Apps API's, but I wouldn't hold your breath waiting.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)