fed Posted June 21, 2011 Posted June 21, 2011 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
comment Posted June 21, 2011 Posted June 21, 2011 Is there a way to send a command to Terminal in OSX without using applescript? Why must it be "without using applescript"?
fed Posted June 21, 2011 Author Posted June 21, 2011 Because applescript is slow. Do you know of another way?
bruceR Posted June 21, 2011 Posted June 21, 2011 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.
comment Posted June 21, 2011 Posted June 21, 2011 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.
bruceR Posted June 22, 2011 Posted June 22, 2011 Do you know the answer? Simple example attached. ShellFindExample.fp7.zip
iMarcW Posted June 22, 2011 Posted June 22, 2011 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
bruceR Posted June 22, 2011 Posted June 22, 2011 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.
fed Posted June 22, 2011 Author Posted June 22, 2011 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
comment Posted June 22, 2011 Posted June 22, 2011 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.
fed Posted June 24, 2011 Author Posted June 24, 2011 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 )
comment Posted June 24, 2011 Posted June 24, 2011 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.
bruceR Posted June 25, 2011 Posted June 25, 2011 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
fed Posted June 25, 2011 Author Posted June 25, 2011 "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?
bruceR Posted June 25, 2011 Posted June 25, 2011 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.
fed Posted June 25, 2011 Author Posted June 25, 2011 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."
bruceR Posted June 25, 2011 Posted June 25, 2011 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.
fed Posted June 26, 2011 Author Posted June 26, 2011 Here you go. Thank you for your help. PatientDocuments.fp7.zip
comment Posted June 26, 2011 Posted June 26, 2011 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
fed Posted June 26, 2011 Author Posted June 26, 2011 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.
comment Posted June 26, 2011 Posted June 26, 2011 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'"
fed Posted June 26, 2011 Author Posted June 26, 2011 I tried your suggestion, and now I get th error: "Expected “"” but found unknown token." Any further ideas. Thanks again. PatientDocuments.fp7.zip
fed Posted June 27, 2011 Author Posted June 27, 2011 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
comment Posted June 27, 2011 Posted June 27, 2011 I still don't understand why your way works and mine does not. Because you escape and I quote.
bruceR Posted June 27, 2011 Posted June 27, 2011 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.
Recommended Posts
This topic is 4899 days old. Please don't post here. Open a new topic instead.
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 accountSign in
Already have an account? Sign in here.
Sign In Now