Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Send Events to Terminal in OSX

Featured Replies

Is there a way to send a command to Terminal in OSX without using applescript?

I am trying to get a list of SubFolders in a MainFolder, as well as lists of all files in those SudFolders. I will use this list to be able to view PDF files in those folders using a webviewer.

Thank you,

Fed

Is there a way to send a command to Terminal in OSX without using applescript?

Why must it be "without using applescript"?

  • Author

Because applescript is slow.

Do you know of another way?

Because applescript is slow.

Do you know of another way?

This is a broad and inaccurate statement.

Similar to saying "FileMaker is slow".

It depends on knowing details of what you are trying to do and whether you are using appropriate techniques for the task.

  • Author

Do you know the answer?

I don't think using AppleScript to call a shell script will be any slower than doing the same thing through Send Event*. It will be much simpler, though

---

(*) assuming it's even possible.

I've noticed seeing the spinning beachball more often when using AppleScript to do shell commands, especially when using the Calculated AppleScript option, which I believe has to be compiled each time before it runs. Even if the spinning beachball doesn't show for very long, it makes a solution look glitchy and unprofessional compared to not using AS, even with no difference in time elapsed before the script completes.

Anyway, if you're not averse to using plug-ins, the free, cross-platform BaseElements plug-in executes shell commands and does much more:

http://www.goya.com.au/baseelements/plugin

I've noticed seeing the spinning beachball more often when using AppleScript to do shell commands, especially when using the Calculated AppleScript option, which I believe has to be compiled each time before it runs. Even if the spinning beachball doesn't show for very long, it makes a solution look glitchy and unprofessional compared to not using AS, even with no difference in time elapsed before the script completes.

Anyway, if you're not averse to using plug-ins, the free, cross-platform BaseElements plug-in executes shell commands and does much more:

http://www.goya.com.au/baseelements/plugin

Again you need to describe exactly what you're doing. Do shell is usually way simple and way fast.

  • Author

I am getting the feeling from the responses that there is NOT a way to do "Send Events" for Terminal commands in OSX, and I MUST use applescript "Do shell script" instead. Can anyone confirm this?

Thank you,

Fed

I don't have a definite answer for you, only a few thoughts:

The Send Event script step will not let you choose Terminal as the target application;

The Send Event script step is very poorly documented - in fact, I believe there is no documentation whatsoever that would apply to Mac OS X;

The concept of Apple Events as such is a carry over from the previous Mac OS. Today, if you want to know what events an application will respond to, you need to open its dictionary in AppleScript Editor - and the information is given to you in AppleScript syntax, not as Apple Events codes. That's understandable, because AppleScript is just a wrapper for Apple Events;

AppleScript can call a shell script directly, without requiring Terminal or another application. It can also get the result and return it to Filemaker.

  • Author

Thank you for your help.

  • Author

I cannot get this to work. Do you find anything wrong with the following? I am using it as a calculated applescript:

"do shell script " & Quote ( "mv /Volumes/Medicine/PatientDocuments/ToFile/" & Substitute ( $Name ; " " ; "\ " ) & "/" & Substitute ( $Document ; " " ; "\ " ) & " /Volumes/Medicine/PatientDocuments/Filed/" & Patient Documents::ID )

I cannot follow this without the context. I suggest you set a global field to the result of your calculation and see if it makes sense.

I cannot get this to work. Do you find anything wrong with the following? I am using it as a calculated applescript:

"do shell script " & Quote ( "mv /Volumes/Medicine/PatientDocuments/ToFile/" & Substitute ( $Name ; " " ; "\ " ) & "/" & Substitute ( $Document ; " " ; "\ " ) & " /Volumes/Medicine/PatientDocuments/Filed/" & Patient Documents::ID )

1. What isn't working? The shell command is not written properly.

I note that you did not put a trailing slash on the target folder; so the result, if it DID work is that assuming the docID is 1275

/Volumes/Medicine/PatientDocuments/ToFile/Sam Smith/xray analysis.doc

becomes:

/Volumes/Medicine/PatientDocuments/Filed/1275

2. I would suggest doing it more like this but it really is not clear what you are trying to to with the document ID.

set sourcefile to "/Volumes/Medicine/PatientDocuments/ToFile/" & $name & "/" & $document

set targetfolder to "/Volumes/Medicine/PatientDocuments/Filed/" & Patient Documents::ID & "/"

set cmd to "mv " & quoted form of sourcefile & " " & quoted form of targetfolder

do shell script cmd

  • Author

"1. What isn't working? The shell command is not written properly.

I note that you did not put a trailing slash on the target folder; so the result, if it DID work is that assuming the docID is 1275"

That is what I am trying to do. I import the jpg into the database, then move and file the original, with a new filename using the serial ID that the database gives it. I get rid of the patient folders to avoid confusion.

I tried what you suggested and it still does not work.

Any further suggestions?

1. What i suggested works.

2. You were not able to make it work. There is no way for us to know why; until you upload a simplified example file that demonstrates what you have attempted and what you have interepreted.

3. Please be much more specific. You are telling us that you want to take a file "something.jpg" ; and file it as 1275 with no extension.

I doubt that is what you want to do.

  • Author

You are right. I forgot the ".jpg"

I added it and I still have the same issue.

I get the following error:

"A unknown token can’t go after this identifier."

You are right. I forgot the ".jpg"

I added it and I still have the same issue.

I get the following error:

"A unknown token can’t go after this identifier."

Example file please.

Show us what you're doing.

Of course you get an error: your shell script is not quoted.

do shell script mv /Volumes/Medicine/PatientDocuments/ToFile/Test\ Tester/test.jpg /Volumes/Medicine/PatientDocuments/Filed/26758.jpg

You would have seen this had you followed my advice to inspect the resulting AppleScript visually.

See also:

http://developer.apple.com/library/mac/#technotes/tn2065/_index.html

  • Author

I have tried all kinds of different combination of "quoting" the satement, but I cannot find the right way.

Please let me know the right way.

How about:

Let ( [

source = "/Volumes/Medicine/PatientDocuments/ToFile/" & Patient Documents::Patient Name imported & "/" & Patient Documents::Filename imported ;

target = "/Volumes/Medicine/PatientDocuments/Filed/" & Patient Documents::ID & ".jpg"

] ;

"do shell script " & Quote ( "mv '" & source & "' '" & target &"'" )

)






I haven't tested it, obviously, but the result in your example is:




do shell script "mv '/Volumes/Medicine/PatientDocuments/ToFile/Test Tester/test.jpg' '/Volumes/Medicine/PatientDocuments/Filed/26758.jpg'"

  • Author

I tried your suggestion, and now I get th error: "Expected “"” but found unknown token."

Any further ideas. Thanks again.

PatientDocuments.fp7.zip

I tried your suggestion

No you didn't.

  • Author

You are correct. I thought it was the same thing, but I tried it your way exactly. It works. Thank you so much.

This is why I wanted to avoid applescript. I always get confused and spend many hours trying to do things that should be really easy. I still don't understand why your way works and mine does not.

Tank you again,

Fed

I still don't understand why your way works and mine does not.

Because you escape and I quote.

You are correct. I thought it was the same thing, but I tried it your way exactly. It works. Thank you so much.

This is why I wanted to avoid applescript. I always get confused and spend many hours trying to do things that should be really easy. I still don't understand why your way works and mine does not.

Tank you again,

Fed

But this had nothing to do with applescript. This is about writing accurate shell scripts.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.