AppleScript or Shell Script?

Hi,
I am trying to paste the clipboard’s content into TextEdit (which is already open), so I need to call an AppleScript which will set focus to TextEdit, and then pastes the clipboard’s content into it.

The questions I have therefore, are:

  1. Does this even need to be performed via applescript, or is there some kind of shell script which will set focus to an app, and then paste in the clipboard’s content?
  2. If AppleScript is needed - how do I call an applescript from within Xojo, and where do I need to put the actual AppleScript file?

Thank you all in advance.

You can use the osascript command from a shell. Will not work in a sandbox without a scripting-targets entitlement or temporary-exception.apple-events though…

Oh - now Im lost?
My app is the the MAS, and I need to set focus to another app, and then paste in the clipboard’s content.

Are you saying this is not possible if my app is sandboxed for the MAS?
I know nothing about scripting-targets entitlements or temporary-exception.apple-events???

Thanks.

You should be able to add an apple events entitlement for “com.apple.security.temporary-exception.apple-events” for “com.apple.TextEdit”

I don’t think you’d have a problem with the MAS since TextEdit is scriptable and doesn’t support scripting-targets. Scripting Terminal.app or Finder.app would be another story…

The other issue is that you likely need to use “System Events” from your applescript, which requires assistive access to be enabled by the user, and could complicate things further… You might be better off (sandbox-wise) setting the text of the front document in TextEdit to add your text rather than pasting…

Hmm…what about this - is it possible to paste the clipboard content into the Xojo IDE, by clicking a button in my MAS app.

For example - I have the Xojo IDE open and wish to paste code from my MAS app, into the Xojo code editor.
If this cannot be done without some serious workarounds, then I will have to forget the idea.

It looks like System Events is prohibited from the MAS… I don’t know of another way to paste into another app.

It’s too bad, because in a non-MAS app you could do somthing like

tell application "System Events" tell application process "TextEdit" set value of attribute "AXSelectedText" of text area 1 of scroll area 1 of window 1 to "something else" end tell end tell

Instead of pasting into TextEdit, why not prepare an rtfd bundle ? TextEdit is probably the only app capable to open that, so using Launch will simply open the document in TextEdit.

What would be perfect is if I could paste a textfield’s content from my MAS app, into the Xojo IDE - but obviously that doesn’t seem possible, so I will have to forget that idea :frowning:

Thanks guys for trying to find a solution :slight_smile:

Does it need to use System Events? I communicate between my (admittedly non-MAS) app and BBEdit extensively with Applescripts along the line of:

tell application "BBEdit" set selection of window 1 to "blah" end tell

Can a MAS app use an Applescript to talk directly to another app directly, rather than through System Events?

Scott,
I have the following applescript file, which will paste the clipboard’s content into Xojo - but it seems it is not allowed in a MAS app??

on run tell application "Xojo" activate tell application "System Events" keystroke "v" using {command down} end tell end tell end run

Well it looks like if you need to get around System Events, your target app needs to be Applescript-friendly. Xojo, in this context, is not. Doesn’t appear to even have a dictionary.

And that assumes that you are trying to programmatically paste the contents of the clipboard into the Xojo IDE. Is that in fact what you want to do, because you mentioned TextEdit earlier.

Ok - my ultimate goal, is to be able to get text from a text area in my MAS app, into the (already open) Xojo IDE on the user’s system.
I do not mind how it’s done, as long as it is possible.

Text Edit was just a test example, but Xojo is the actual app I eventually need to get the text into.
I was under the impression that Xojo was applescript friendly - I must have been mistaken then?

Hope that made more sense :slight_smile:

I think that would require Xojo making the IDE Applescriptable.

Ok - I just ran my applescript from within the AppleScript Editor (locally), and it inserted the text correctly in the Xojo IDE.

So the real question is:
Is this possible from a MAS app - but Jim say’s this is not allowed - so it looks like AppleScript is out of the question :frowning:

[quote=166094:@Richard Summers]Ok - I just ran my applescript from within the AppleScript Editor (locally), and it inserted the text correctly in the Xojo IDE.

So the real question is:
Is this possible from a MAS app - but Jim say’s this is not allowed - so it looks like AppleScript is out of the question :([/quote]

As long as you do not use system events you should be fine. This creates a new document and pastes a string into it.

tell application "TextEdit" make new document end tell tell front document of application "TextEdit" set paragraph 0 to "bla" end tell

All you need is the entitlement to script com.apple.textedit.

Michel - that would work to hardcode text into TextEdit - thanks.

But how would this work with Xojo??
I still cannot see how I can get a text area’s text, from my app into the Xojo IDE??

Surely to paste text from my app into the Xojo IDE - it would need to use System Events?

Thanks.

Richard, I think what people are saying is that if Xojo does not have an AppleScript dictionary that supports setting text or pasting from the clipboard, then the only option is to use System Events to paste (as you are doing). However, using System Events is forbidden in the Mac App Store, so your application would be rejected. So, if this is critical to your application, it would not be able to be offered on the MAS. There is no way around this. Apple prevents allowing any scripting of System Events in MAS applications because can be a huge security risk.

The best way is not to go TextEdit, but to have a TextArea that plays that role within the app. I cannot find that at the moment, but I remember seeing some pretty impressive declares that bring TextEdit style features to it described in this forum.