I am writing an AppleScript program that interacts with iMessage. In order for the script to work, the user needs to configure the 'AppleScript Handler' in iMessage preferences.
The user must choose a script from the ~/Library/Application Scripts/com.apple.iChat folder. I have written a shell script to move my script to that ~/Library/... folder, but how can I write a shell script to automatically select my script from the list of scripts in the iMessage configuration? Is this even possible? Is this the right forum to ask a question like this? Thanks.
Related
Is the script hidden from the user of the application after it is exported as run only?
Tried searching this over internet, but couldn't find the exact answer. Any help is appreciated.
Edit after answers:
Once the script is exported to an application and the script is deleted. Is there a way for the app user to see/manipulate the script from the application content files?
It is not hidden, but it cannot be opened and edited in an AppleScript editor.
I wrote a shell script that I'm distributing to my friends. On my computer, it works great, because I set the default application for shell scripts to be Terminal. However, when my friends open it, the script opens in TextEdit. Is there a way to add an argument to the shell script before it launches so it opens in Terminal instead of a text editor?
Thanks
PS, I did chmod a+x to the file. I also made sure to add #!/bin/sh to the script. I've also been testing with using the extensions .command, .cmd, and .tool. That would solve my problem except then Gatekeeper won't let the script run because I'm not a registered Apple Developer.
If there were a way to make double-clicking a file run it, then that would be the sort of security hole that Gatekeeper is designed to prevent. So, Apple has plugged any such holes they can think of.
Send the file to your friends as a .command file and tell them to right-click or Control-click on it and choose Open. This will change the Gatekeeper dialog to a warning, but with an "Open" button to let them go ahead and open it anyway. The system will prompt them for an administrator password to record the grant of permission in a permanent way. They'll be able to open with a simple double-click from then on.
We have a script to send email using Microsoft outlook or Apple mail application. It will dynamically load the default email from system preference (maybe user input also), and using it to decide which mail client to use.
So the code is as following:
if (mailClientStr contains "outlook")
tell application id "com.microsoft.outlook"
-- <<< there will be error if there is no outlook installed
-- <<< even else branch will be run.
...
end tell
else
tell application id "com.apple.mail"
...
end tell
end if
On an machine which doesn't have outlook installed, and the mailClientStr will be "com.apple.mail", but this script cannot be run by osascript
It complains Can’t get application id "com.microsoft.outlook" even the first branch will not be executed. My understanding is osascript will need to access Outlook apple script interface when load and compile this script (before run it).
I can separate the outlook related code into a separate script, but because there is a lot of data to passing, it will be complex, so I don't want this workaround.
So does there any solution from the apple script language side?
From the AppleScript Language Guide:
Entering Script Information in Raw Format
You can enter double angle brackets, or chevrons («»), directly into a script by typing Option-Backslash and Shift-Option-Backslash. You might want to do this if you’re working on a script that needs to use terminology that isn’t available on your current machine—for example, if you’re working at home and don’t have the latest dictionary for a scriptable application you are developing, but you know the codes for a supported term.
You can also use AppleScript to display the underlying codes for a script, using the following steps:
Create a script using standard terms compiled against an available application or scripting addition.
Save the script as text and quit Script Editor.
Remove the application or scripting addition from the computer.
Open the script again and compile it.
When AppleScript asks you to locate the application or scripting addition, cancel the dialog.
Script Editor can compile the script, but displays chevron format for any terms that rely on a missing dictionary
I want to associate the .exe file extension with a shell script that launches wine. What is the best way to do this?
From what I've gathered, I need to create an AppleScript that will call wine, but how do I get the name of the input file in the AppleScript? If there is a better way to do this, let me know, but as far as I know this is the best way.
You can also use Automator to wrap your own bash, python or ruby script in an "Application".
Open Automator and choose to create an Application.
Find the Action "Run Shell Script" and double-click it or drag it to the script area.
Select the interpreter you want (bash, other shells, python or ruby).
Set the "Pass input" option to "as arguments". (In the automator model, the application "receives files and folders as input"; hence this lets your script see filenames as commandline arguments).
Enter your shell script in the edit area. On bash, use "$#" for the list of commandline arguments (individually quoted to protect embedded spaces).
You can now save the script (it will get a .app extension), and move it to the Applications folder or other reasonable location. It can be associated with a file type, like any other application.
NOTE: This works on Mountain Lion (10.8); can someone comment on how long Automator has been able to do this?
You can use an AppleScript application to do this - files are passed to the open handler, the same as a droplet, for example:
on open theFiles
set arguments to ""
repeat with anItem in theFiles
set arguments to arguments & space & (quoted form of POSIX path of anItem)
end repeat
do shell script "/path/to/wine" & arguments
end open
To associate a particular document type with your application, you will first need to add information to your application's information property list (Info.plist) to tell Launch Services what types of documents it can handle. See Apple's Document-Based Applications Overview (or take a look at the settings in other applications).
I have a user script that would be much more useful if it could dynamically change some of its execution dependent on what the user wanted. Passing simple switches would easily solve this problem but I don't see any way to do it.
I also tried embedding a keyword in the script name, but Xcode copies the script to a guid-looking filename before execution, so that won't work either.
So does anyone know of a way to call a user script with some sort of argument? (other that the normal %%%var%%% variables)
EDIT:
User scripts are accessible via the script menu in Xcode's menubar (between the Window and Help menus). My question is not about "run script" build phase scripts. My apologies for leaving that somewhat ambiguous.
You can't pass parameters to user scripts — instead, user scripts operate on the context you're working in (e.g. the selected file, the selected text, etc.).
You should use the context to determine what the user really wants.
User scripts are accessible via the script menu in Xcode's menubar (between the Window and Help menus). Wasn't sure what else to call them. What I'm asking about are not "run script" build phase scripts.
I suppose you could do something like this:
#!/bin/bash
result=$( osascript << END
tell app "System Events"
set a to display dialog "What shall be the result?" default answer ""
end tell
return text returned of a
END
)
# do stuff with $result
There are built in utility scripts that allow you to prompt the user and capture the reply.
You could prompt for a string, for example, then based on that perform a certain task.
The String prompt is:
STRING = `%%%{PBXUtilityScriptsPath}%%%/AskUserForStringDialog "DefaultString" "DefaultWindowName"`
If you notice, you're just calling an applescript they wrote using a static path. You could write your own applescript dialog and place it there if you want and bypass the need for cumbersome osascript syntax. There are others (for files, folders, applications, etc)
User Scripts Documenation