Jump to content

Copy equation result to clipboard in AppleScript


Recommended Posts

Posted (edited)

I'm trying to make a script to help in calculating em values. I feel really dumb asking this, but I can't for the life of me figure out how to get the result copied to the clipboard, for pasting into other applications. Here's what I have so far:

set query to {query}
set base_em to 16
set calculated_em to query / base_em
calculated_em as real
get calculated_em
set the clipboard to calculated_em

Essentially, the workflow will be typing em {query}, then ⏎, copying the result to the keyboard. I've got everything working until the clipboard part - I'm sure I'm missing something totally obvious here, but I can't for the life of me figure out the last part, argh.

Edited by ericwbailey
Posted

Try:

try
    
    set query to "{query}" as number
    set base_em to 16
    set calculated_em to query / base_em
    set the clipboard to calculated_em as text
    
on error errMsg number errNum
    tell application "Finder"
        activate
        display alert errMsg & return & return & "Error number" & errNum buttons "Cancel" cancel button "Cancel"
    end tell
end try
Posted

I'm trying to make a script to help in calculating em values. I feel really dumb asking this, but I can't for the life of me figure out how to get the result copied to the clipboard, for pasting into other applications. Here's what I have so far:

set query to {query}
set base_em to 16
set calculated_em to query / base_em
calculated_em as real
get calculated_em
set the clipboard to calculated_em

Essentially, the workflow will be typing em {query}, then ⏎, copying the result to the keyboard. I've got everything working until the clipboard part - I'm sure I'm missing something totally obvious here, but I can't for the life of me figure out the last part, argh.

 

Here is an AppleScript code that seems to be working:

set query to "{query}" as text
set base_em to 16
set calculated_em to (query / base_em) as real
set the clipboard to calculated_em as text 

And here is the workflow I did to test it: download now

Posted

Here is an AppleScript code that seems to be working:

set query to "{query}" as text
set base_em to 16
set calculated_em to (query / base_em) as real
set the clipboard to calculated_em as text 

And here is the workflow I did to test it: download now

 

 

This worked perfectly! Thanks for the quick replies, guys. It totally makes sense in hindsight.

  • 1 year later...
Posted

I've been playing with a simple workflow and ran into a problem similar to the above.

 

We use a simple script to tell each other where files are stored on our server…

 

tell application "Finder"

selection as alias as string

end tell

 

Gives a result like this > "Macintosh SSD:Users:threezero:Desktop:Version6.png"

 
It would be great if we could get the result copied to clipboard.
 
Any ideas gratefully received.
 
Stephen
 
Posted (edited)

 

I've been playing with a simple workflow and ran into a problem similar to the above.

 

We use a simple script to tell each other where files are stored on our server…

 

tell application "Finder"

selection as alias as string

end tell

 

Gives a result like this > "Macintosh SSD:Users:threezero:Desktop:Version6.png"

 
It would be great if we could get the result copied to clipboard.
 
Any ideas gratefully received.
 
Stephen
 

 

 

One way to do that:

tell application "Finder"
	set sSel to selection as alias as text
end tell

set the clipboard to sSel as text

[update] If there is a chance that multiple files are selected, then:

tell application "Finder"
	set sSel to selection
	set sSel to item 1 of sSel
end tell

set the clipboard to sSel as text
Edited by Carlos-Sz

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...