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

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.

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

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

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?

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

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?

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.