I'm trying to get this applescript to find the placeholder text and replace it based on the return dialog. Maybe someone can see what I have wrong.
set OrderNumber to text returned of (display dialog "OrderNumber:" default answer "60000")
set CustomerPO to text returned of (display dialog "CustomerPO:" default answer "TBD")
set GarmentColor to text returned of (display dialog "GarmentColor" default answer "ASH GRAY")
set GarmentDescription to text returned of (display dialog "GarmentDescription" default answer "T-Shirt")
set DesignID to text returned of (display dialog "DesignID" default answer "TBD")
set DesignTitle to text returned of (display dialog "DesignTitle" default answer "TBD")
set Location to text returned of (display dialog "Location" default answer "TBD")
set InkColors1 to text returned of (display dialog "InkColors" default answer "WH")
tell application "Adobe Illustrator"
activate
end tell
on replace_chars(this_text, "AAA", OrderNumber)
{this_text, "BBB", CustomerPO}
{this_text, "CCC", GarmentColor}
{this_text, "DDD", GarmentDescription}
{this_text, "EEE", DesignID}
{this_text, "FFF", DesignTitle}
{this_text, "GGG", Location}
{this_text, "HH", InkColors1}
t
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
The basic approach is to add custom names to the text frames you're interested in. Just double-click on the item in AI's Layers palette, then type in the desired name. You can then set the text frame's content from AppleScript like this:
tell application "Adobe Illustrator"
tell document 1
set contents of text of text frame "DesignTitle" to "New Text"
end tell
end tell
If you've not already done so, you should also get yourself a copy of Adobe's AI Scripting Reference. While a lot of the content is just a rehash of information already in AI's dictionary, it does provide some additional details along with example code.
Related
Does anyone know of an applescript that will take whatever is on the clipboard and wrap it in quotes. (Ideally triggered by key shortcut, but i can set that up myself)
Example (Copied Data from excel col)
Beer
Whisky
Chronic
Would turn into
'Beer','Whisky','Chronic'
I can't find this anywhere and I can only do some basic stuff in Applescript but I totally think it would help a lot of devs/db admins!
Assuming the source is plain text and the items are separated by newline characters
you can do it with text item delimiters
set theText to "Beer
Whisky
Chronic"
set {TID, text item delimiters} to {text item delimiters, {linefeed, return}}
set theList to text items of theText
set text item delimiters to "','"
set theResult to "'" & (theList as text) & "'"
set text item delimiters to TID
theResult
To get the data directly from the clipboard replace the first line with
set theText to the clipboard
thanks to #vadian for the help there - the final working script
takes input from clipboard, transforms and then puts back to clipboard
set theText to (do shell script "pbpaste")
set {TID, text item delimiters} to {text item delimiters, {linefeed, return}}
set theList to text items of theText
set text item delimiters to "','"
set theResult to "'" & (theList as text) & "'"
set text item delimiters to TID
set the clipboard to theResult
theResult
I've set it up as a service using automator and assigned a keyboard shortcut for quick transform.
I wan to change the content of the currently composed message and add the string *WF* at the end. Below is the script, I get an error Microsoft Outlook got an error: Can’t set content of draft window id 9490 to ...
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
tell application "Microsoft Outlook"
activate
set theWindow to window 1
-- check it's really draft
if class of theWindow is not draft window then
display dialog "Not a draft"
return
end if
-- save the draft
save theWindow
--get the id of the object of the draft window
set myObjectID to id of (object of theWindow)
-- to make it secure
set myContent to content of message id myObjectID
--edit recipient
-- set theBCC to bcc recipient of message id myObjectID
-- set emailString to theBCC
make new bcc recipient at message id myObjectID with properties {email address:{name:"Ittay Dror", address:"idror#akamai.com"}}
set myContent to my replace_chars(myContent, "</body>", "*WF*</body>")
set the content of theWindow to myContent
end tell
you can't set the content of a window. Please set the content of the message:
set the content of message id myObjectID to myContent
Cheers,
Michael / Hamburg
I would like to be able to send the output of a dialog box to my email. What would be the best way to do such a thing?
It would be something sort of like this:
repeat
display dialog "Enter some text:" buttons {"Git Goin"} default answer ""
set theNewInfo to text returned of result
if theNewInfo ≠ "" then exit repeat
end repeat
Its a really simple script for a proof of concept, but what I want is as follows: When they enter any text into the dialog box, for that text to be sent to my email, regardless of what it contains.The Subject would say "NewInfo" and the body would contain the text entered into the dialog box
You should post what code you have... too many questions still to be able to answer you reliably. What are you wanting to send to the email message? email addy? subject? body? etc.
Basically, you capture the result of the dialog and then put it into a "mailto:" URL string and then use 'open location' on the URL. This should be enough to get you started:
set dialogResult to display dialog "Enter the subject" default answer "My subject" buttons {"me#example.com", "you#example.com"} default button 1
set theAddress to button returned of dialogResult
set theSubject to text returned of dialogResult
set theBody to "This%20is%20the%20body%20text:%0AMore%20text"
-- Must encode entities, spaces as %20 and line breaks as %0A (%0D%0A), etc.
set theSubject to findReplace(" ", "%20", theSubject)
set theSubject to findReplace(return, "%0A", theSubject)
set theURL to "mailto:" & theAddress & "?subject=" & theSubject & "&body=" & theBody
open location theURL
on findReplace(f, r, s)
set otid to AppleScript's text item delimiters
set AppleScript's text item delimiters to f
set s to text items of s
set AppleScript's text item delimiters to r
set s to s as string
set AppleScript's text item delimiters to otid
return s
end findReplace
I am using the code below to open youtube with google query in applescript as the new google does not carry my search string to youtube.Unable to open url in firefix with the google search string in firefox. I really appreciate any help.Thanks in advance.
I am getting an error here :
tell application "Firefox" to activate
tell application "System Events"
keystroke "l" using command down
keystroke "c" using command down
set tr to get the clipboard
end tell
return trimgoogle(tr)
on trimgoogle(sourceAddress)
set AppleScript's text item delimiters to {"#"}
set addressParts to (every text item in sourceAddress) as list
set AppleScript's text item delimiters to ""
set nameOnly to item 2 of addressParts
set AppleScript's text item delimiters to {"&"}
set addressParts2 to (every text item in nameOnly) as list
set AppleScript's text item delimiters to ""
set nameOnly1 to item 1 of addressParts2
set nameOnly2 to nameOnly1
set AppleScript's text item delimiters to {"="}
set addressParts21 to (every text item in nameOnly2) as list
set AppleScript's text item delimiters to ""
set nameOnly12 to item 2 of addressParts21
set newurl to "http://www.youtube.com/results?search_query=" & nameOnly12
return newurl
end trimgoogle
tell application "Firefox"
OpenURL newurl
end tell
Try this:
tell application "Firefox"
open location newurl
end tell
EDIT:
Firefox does not activate itself automatically, so I just tried this:
tell application "Firefox"
activate
open location "http://www.wikipedia.com/"
end tell
which works here.
Here more about encoding text:
http://www.macosxautomation.com/applescript/sbrt/sbrt-08.html
EDIT2:
OK, I see what you mean, that would be solved like this:
tell application "Firefox" to activate
tell application "System Events"
keystroke "l" using command down
keystroke "c" using command down
set tr to get the clipboard
end tell
set newurl to my trimgoogle(tr)
tell application "Firefox"
activate
open location newurl
end tell
on trimgoogle(sourceAddress)
set AppleScript's text item delimiters to {"#"}
set addressParts to (every text item in sourceAddress) as list
set AppleScript's text item delimiters to ""
set nameOnly to item 2 of addressParts
set AppleScript's text item delimiters to {"&"}
set addressParts2 to (every text item in nameOnly) as list
set AppleScript's text item delimiters to ""
set nameOnly1 to item 1 of addressParts2
set nameOnly2 to nameOnly1
set AppleScript's text item delimiters to {"="}
set addressParts21 to (every text item in nameOnly2) as list
set AppleScript's text item delimiters to ""
set nameOnly12 to item 2 of addressParts21
set newurl to "http://www.youtube.com/results?search_query=" & nameOnly12
return newurl
end trimgoogle
I'm trying to the function replaceChars in the below script but getting the following error:
error "Finder got an error: Can’t continue replace_chars." number -1708
The intention is to add the script to finder as a button so that I can simply click it to copy the path to my clipboard. I'm adding file://localhost/ so that the link can then be used when shared with users by email as a direct link to a folder on the local network. If possible I would also like to add to clipboard the same for Windows machines.
If you could offer any guidance as to the task above it would be much appreciated, this is my first attempt at programming with applescript so I'm not that knowledgable of how things are done.
Heres the code:
on appIsRunning(appName)
tell application "System Events"
set isRunning to ((application processes whose (name is equal to appName)) count)
end tell
if isRunning is greater than 0 then
return true
else
return false
end if
end appIsRunning
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
if appIsRunning("Finder") then
tell application "Finder"
set thePath to "file://localhost/" as text
set theTarget to (target of front Finder window) as text
set the clipboard to thePath & replace_chars(theTarget, ":", "/") as text
end tell
end if
AppleScript is looking for a replace_chars handler in the Finder's scripting dictionary. You can either make it into my replace_chars to have AS look in the script, or (probably better) move the set the clipboard to thePath & replace_chars(theTarget, ":", "/") as text line out of the tell block altogether.
You can make it into a one-line script:
tell application "Finder" to set the clipboard to "file://localhost" & (target of front Finder window as text)'s POSIX path
Replace your replace_chars(theTarget, ":", "/") call with replace_chars(theTarget, ":", "/") of me:
set the clipboard to thePath & replace_chars(theTarget, ":", "/") of me as text