Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
AppleScript "do shell script" Error: "Cant' make...into type string."
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Mark FX" data-source="post: 1726372" data-attributes="member: 211556"><p>Firstly when your activating another application like "Terminal", you have to allow time for the application to activate before passing it more instructions.</p><p>But in this case you don't even need to activate "Terminal", because the "do shell script" command is an "AppleScript" command, and not a "Terminal command, so "Terminal does not understand the instruction.</p><p></p><p>So in the "Script Editor" application, you can simply type this, and hit the run button in the "Script Editor" toolbar to hear and see the shell return result.</p><p></p><p>[CODE]</p><p>do shell script "say hello"</p><p>[/CODE]</p><p></p><p>The Result display pane is at the bottom of the "Script Editor" applications window.</p><p>In the case of the simple script above, the return result is an empty string, as this shell command does not have a return value.</p><p></p><p>If you type your second example into the "Script Editor" like below, and hit the run button, you will see the returned result in the result pane as a string.</p><p></p><p>[CODE]</p><p>do shell script "system_profiler SPHardwareDataType"</p><p>[/CODE]</p><p></p><p>You can then do something with the rsult if you typed your script like this.</p><p></p><p>[CODE]</p><p>set myResult to do shell script "system_profiler SPHardwareDataType"</p><p>-- Do something with the myResult variable</p><p>return myResult</p><p>[/CODE]</p><p></p><p>I hope this helps.</p><p>But I would recommend learning the basics of AppleScript before moving on to more complex examples.</p><p>There are plenty of free online resources for learning AppleScript.</p><p></p><p>And in recent times you can even create fully fledged applications in Xcode with Applescript, and create a custom user interface for your applications as well.</p><p></p><p>Regards Mark</p></blockquote><p></p>
[QUOTE="Mark FX, post: 1726372, member: 211556"] Firstly when your activating another application like "Terminal", you have to allow time for the application to activate before passing it more instructions. But in this case you don't even need to activate "Terminal", because the "do shell script" command is an "AppleScript" command, and not a "Terminal command, so "Terminal does not understand the instruction. So in the "Script Editor" application, you can simply type this, and hit the run button in the "Script Editor" toolbar to hear and see the shell return result. [CODE] do shell script "say hello" [/CODE] The Result display pane is at the bottom of the "Script Editor" applications window. In the case of the simple script above, the return result is an empty string, as this shell command does not have a return value. If you type your second example into the "Script Editor" like below, and hit the run button, you will see the returned result in the result pane as a string. [CODE] do shell script "system_profiler SPHardwareDataType" [/CODE] You can then do something with the rsult if you typed your script like this. [CODE] set myResult to do shell script "system_profiler SPHardwareDataType" -- Do something with the myResult variable return myResult [/CODE] I hope this helps. But I would recommend learning the basics of AppleScript before moving on to more complex examples. There are plenty of free online resources for learning AppleScript. And in recent times you can even create fully fledged applications in Xcode with Applescript, and create a custom user interface for your applications as well. Regards Mark [/QUOTE]
Verification
Name this item. 🍎
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
AppleScript "do shell script" Error: "Cant' make...into type string."
Top