How would I create an icon that would open the terminal into a specific directory? Could also be into the directory where the icon lives.
You can use "Automator" this way:
Create an automator application
Add a "Run Script Applescript" action
Modify the code to:
on run {input, parameters}
tell application "terminal"
activate
set UnixPath to POSIX path of ((path to me as text) & "::")
do script with command "cd " & UnixPath
end tell
end run
Save it
Run it! Move it where you want, Run it...
Finally found the easiest answer to this: use Finder services. See http://www.howtogeek.com/210147/how-to-open-terminal-in-the-current-os-x-finder-location.
Related
I want to open an org-mode file selected in the Finder, by double clicking on it. But since I use Emacs in daemon-mode, I want to use the emacsclient command for that.
Thus the primary idea was to wrap the command emacsclient -c posixPathToFile in an AppleScript App to open it.
tell application "Finder"
set fileAlias to the selection as alias
set fileName to name of fileAlias
set posixPath to POSIX path of fileAlias
end tell
-- tell application "Emacs" to activate
try
do shell script "/usr/local/bin/emacsclient -c " & quoted form of posixPath
end try
I know some set commands are not needed. Let's assume this script is saved as Xemacs.app and that I associate this app to always open .org file.
Using this App does not work by double-clicking on the file, but rather if I select the file in the Finder and then call the Xemacs.app independently. Why ? I'm not confident enough with AppleScript to figure out what happens.
So the workaround was to use the Automator service
on run {input, parameters}
set posixPath to POSIX path of input
tell application "iTerm" to do shell script "/usr/local/bin/emacsclient -c " & quoted form of posixPath
return input
end run
The service is saved as 'Open in Emacs'
Now selecting a file and right-clicking and callig Service > "Open in Emacs" works and opens the file.
What is wrong with the first approach ?
ok, I solved my issue. The problem comes from my misunderstanding of the difference between ScriptEditor and the Automator. If I use the Automator to create an App and use the former script instead of creating an App using the ScriptEditor, then it works as expected.
One can simplify the process by creating an App in Automator and running a shell script instead of wrapping the command in Ascript.
I've created an AppleScript that runs a bash script and launches an application
I've saved the AppleScript as an application
On my computer, the bash script runs and so does that application; however, on another computer the AppleScript can't open the application because its from an unidentified developer
Is there a way to have the AppleScript open the application even though it's from an unidentified developer? Oris there a way to open the application with a bash script?
I know how to open an app inside a bash script, but it runs into the same issue (unidentified developer error)
I'm not looking to change my system preferences. I'm looking for a way to do it programmatically so any user can run the AppleScript on their machine
It's OK if the user has to "right-click, open" the final AppleScript to make the Apple Script run, it just needs to open the application that script is opening up without having to "right-click, open" again
Here is my AppleScript code:
tell application "Finder" to get POSIX path of ((path to me as text) & "::")
set scriptPath to quoted form of result & "BrewInstall.command"
tell application "Finder" to get POSIX path of ((path to me as text) & "::")
set appPath to result & "OracleInstall.app"
tell application appPath
activate
end tell
tell application "Terminal"
activate
do script scriptPath
end tell
If you first remove the quarantine attribute, it should work:
do shell script "xattr -d com.apple.quarantine & appPath
I have this automator setup which allows you to open a folder with terminal. The thing I want is that after the folder is opened via terminal, it should run the compass watch script.
This is what I currently have but I don't seem to find the solution myself. I tried adding some applescript and some bash, but nothing seems to work. Anyone know the solution?
Try this :
Add the "Run AppleScript" action in your workflow
If the compass watch script is a file, use this AppleScript script
on run {input, parameters}
set compasswatchScript to quoted form of "" -- drag drop the script file between double quote
tell application "Terminal"
do script compasswatchScript in window 1
end tell
end run
Insert the path of your script file in the second line of this script
--
if compass watch is a command, use this AppleScript script
on run {input, parameters}
tell application "Terminal"
do script "compass watch" in window 1
end tell
end run
I´m trying to create a keyshortcut to open terminal in current folder. Looking around, I found this code to create a service (the part of adding the shortcut to this service is solved), only added things are the "; clear" and some of the "activate" so it shows
on run {input, parameters}
tell application "Finder"
activate
set myWin to window 1
set theWin to (quoted form of POSIX path of (target of myWin as alias))
tell application "Terminal"
activate
tell window 1
activate
do script "cd " & theWin & ";clear"
end tell
end tell
end tell
return input
end run
It is not working as i would like.
troubles:
it opens two windows in terminal, have no idea why. It has nothing to
do with the added "activate"… it has always donde that
if I select an item on finder ( a folder ) it opens its parent directory and i would
like it to open the selected folder
this is my very first try with Applescript so if the error is obvious i just can't see it
Thanks in advance
The do script command already opens a window in Terminal. Try it this way:
tell application "Finder" to set theSel to selection
tell application "Terminal"
set theFol to POSIX path of ((item 1 of theSel) as text)
if (count of windows) is not 0 then
do script "cd " & quoted form of theFol & ";clear" in window 1
else
do script "cd " & quoted form of theFol & ";clear"
end if
activate
end tell
I like the reopen approach better...
tell application "Finder" to set currentFolder to target of front Finder window as text
set theWin to currentFolder's POSIX path
tell application "Terminal"
if not (exists window 1) then reopen
activate
do script "cd " & quoted form of theWin & ";clear" in window 1
end tell
I am using Applescript to automate some tasks in the OSX Finder. The script opens up a folder and selects the first image in that folder. I would like it to also bring up the "quick look" window (exactly as if the user had pressed the space bar).
I did find a way to fire up quick look from the command line using qlmanage, but that brings up a static quick look window, which is no longer tied to the finder selection.
Code so far:
property folderPath : "/Volumes/Media/Images"
on run {}
tell application "Finder"
activate
set imageFolder to folder (folderPath as POSIX file)
set imageFile to first item of imageFolder
select imageFile
-- show quick look?
end tell
end run
If you don't want to do it by scripting the Finder you can run the following shell command
qlmanage -p thefile
In an Applescript you might do this like
do shell script "qlmanage -p " & "thepath/thefile"
Depending upon what you are doing this might be much easier. Especially if you primarily just have a set of paths.
If you have an existing Applescript path you can send it like this
set p to POSIX path of mypath
do shell script "qlmanage -pr " & quoted form of p
Updated (with thanks to Kevin Ballard):
tell application "System Events" to keystroke "y" using command down
Note: this requires that "enable access for assistive devices" is selected in the "Universal Access" control panel.