Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8434995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:48:40+00:00 2026-06-10T06:48:40+00:00

I have tried to make an AppleScript that is supposed to read the current

  • 0

I have tried to make an AppleScript that is supposed to read the current directory from Finder and run a shell command on it. If I navigate to the desired folder in Finder and run the script from AppleScript Editor it works, but when I saved the script and dragged it to the Finder toolbar, currentDir is set to the folder of the script file (my user directory). Here is my script:

tell application "Finder"
    set currentDir to POSIX path of ((container of (path to me)) as text)
end tell
tell application "Terminal"
    do script "cd " & currentDir
    do script "<operation goes here>"
end tell

How can I get the directory active when I use the toolbar shortcut?
Second, is there a way to run the shell command in the background, without opening (showing) the Terminal window?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:48:41+00:00Added an answer on June 10, 2026 at 6:48 am

    Here are two solutions:

    1- If the current folder is the target of the front Finder window :

    tell application "Finder" to set currentDir to (target of front Finder window) as text
    do shell script "cd " & (quoted form of POSIX path of currentDir) & "; <operation goes here>"
    

    —

    2
    – If the current folder is the selected folder, it will be different in ( list view or coverflow) with respect to the target of the window, because you can select a sufolder in the window (the target of the window will not change) :

    tell application "Finder"
        set sel to item 1 of (get selection)
        if class of sel is folder then
            set currentDir to sel as text
        else
            set currentDir to (container of sel) as text
        end if
    end tell
    do shell script "cd " & (quoted form of POSIX path of currentDir) & "; <operation goes here>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to make a function that iterates through the following array to
I have tried to make the fullscreen feature of a SDI application with splitter
This might get a little confusing as I have tried everything to make this
How to make a sticky footer i have tried on google found some results
How do I make the following url forbidden in apache; main/index.php?site=ing I have tried
I tried to make admin panel and I am using sessions , but have
I am wondering if you have tried to make a mobile version of a
I have a Database that uses a string to get information from the data
If I have an applescript snippet such as this tell application Finder set thePath
I have tried to make method which changes one color of BufferedImage to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.