# Script help needed: clear selection; select current object

**URL:** <https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225>\
**Category:** Help & Support\
**Created:** [April 28, 2014, 3:01pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225 "2014-04-28T15:01:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Axonn](https://resource.dopus.com/user_avatar/resource.dopus.com/axonn/32/12524_2.png) [@Axonn](https://resource.dopus.com/u/Axonn)\
**Post date:** [April 28, 2014, 3:01pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/1 "2014-04-28T15:01:29Z")

</div>

Both these questions apply to Power Mode

Is there a command in Directory Opus to clear the current selection?

Is there a command to select the current object (file or folder on which the caret is). What I want to do with this is to start a copy of the object the caret is on when I press F5 (like in Total Commander when you don't have to actually select an item you're caret-ing on when you want to copy it).

---

<div class="post-metadata">

**Author:** ![Jon](https://resource.dopus.com/user_avatar/resource.dopus.com/jon/32/12713_2.png) [@Jon](https://resource.dopus.com/u/Jon)\
**Post date:** [April 28, 2014, 3:13pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/2 "2014-04-28T15:13:40Z")

</div>

The two commands are Select NONE and Select THIS.

---

<div class="post-metadata">

**Author:** ![Axonn](https://resource.dopus.com/user_avatar/resource.dopus.com/axonn/32/12524_2.png) [@Axonn](https://resource.dopus.com/u/Axonn)\
**Post date:** [April 28, 2014, 3:44pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/3 "2014-04-28T15:44:55Z")

</div>

Thanks. It kind of works 😉. I tried:

`@script jscript
function OnClick(data){
   data.func.command.RunCommand("Select THIS");
   data.func.command.RunCommand("Copy");
}`

Unfortunately, this requires me to press F5 _twice_ in order to work. First, it selects the object, but does not copy. Pressing F5 again copies it. Ideas? 🙂.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [April 28, 2014, 4:10pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/4 "2014-04-28T16:10:28Z")

</div>

The objects take a snapshot of things like the selected files at the start. If they change and you want the objects to use the new selections, you need to update them:

`@script jscript
function OnClick(data){
   data.func.command.RunCommand("Select THIS");
   data.func.command.sourcetab.Update();
   data.func.command.SetFiles(data.func.command.sourcetab.selected_files);
   data.func.command.RunCommand("Copy");
}`

---

<div class="post-metadata">

**Author:** ![Axonn](https://resource.dopus.com/user_avatar/resource.dopus.com/axonn/32/12524_2.png) [@Axonn](https://resource.dopus.com/u/Axonn)\
**Post date:** [April 29, 2014, 12:50pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/5 "2014-04-29T12:50:43Z")

</div>

Excellent. Thank you very much 🙂.

---

<div class="post-metadata">

**Author:** ![Axonn](https://resource.dopus.com/user_avatar/resource.dopus.com/axonn/32/12524_2.png) [@Axonn](https://resource.dopus.com/u/Axonn)\
**Post date:** [April 29, 2014, 1:02pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/6 "2014-04-29T13:02:35Z")

</div>

Ah. Whoops. Doesn't work. Same thing. Gets selected but not copied.

---

<div class="post-metadata">

**Author:** ![Axonn](https://resource.dopus.com/user_avatar/resource.dopus.com/axonn/32/12524_2.png) [@Axonn](https://resource.dopus.com/u/Axonn)\
**Post date:** [April 29, 2014, 1:06pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/7 "2014-04-29T13:06:53Z")

</div>

Hm. Interesting. Now it does NOT copy even when I hit F5 a second time.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [April 29, 2014, 1:16pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/8 "2014-04-29T13:16:18Z")

</div>

It worked here on a toolbar button. I didn't try on a hotkey but it should behave in the same way, as long as there isn't another hotkey on the same thing (F5 is the standard hotkey for "refresh", so that isn't impossible).

---

<div class="post-metadata">

**Author:** ![Axonn](https://resource.dopus.com/user_avatar/resource.dopus.com/axonn/32/12524_2.png) [@Axonn](https://resource.dopus.com/u/Axonn)\
**Post date:** [April 29, 2014, 1:32pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/9 "2014-04-29T13:32:56Z")

</div>

I deselected the other function of F5 (unchecked its checkbox).

The new script only selects items (just like the one I posted earlier) but unlike the earlier script, doesn't copy when I press F5 a second time.

I uploaded proof 😃.

 ![](https://resource.dopus.com/uploads/default/original/3X/7/b/7b2fd6ec0bb6deb1978b247e2d2feea2e199dfb0.png)

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [April 29, 2014, 6:38pm UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/10 "2014-04-29T18:38:05Z")

</div>

Did you try with a file or a folder?

I think the script as it was would only copy files.

If you change selected\_files to selected it should work with both:

`@script jscript
function OnClick(data){
   data.func.command.RunCommand("Select THIS");
   data.func.command.sourcetab.Update();
   data.func.command.SetFiles(data.func.command.sourcetab.selected);
   data.func.command.RunCommand("Copy");
}`

---

<div class="post-metadata">

**Author:** ![Axonn](https://resource.dopus.com/user_avatar/resource.dopus.com/axonn/32/12524_2.png) [@Axonn](https://resource.dopus.com/u/Axonn)\
**Post date:** [April 30, 2014, 6:32am UTC](https://resource.dopus.com/t/script-help-needed-clear-selection-select-current-object/18225/11 "2014-04-30T06:32:05Z")

</div>

It was with a folder 🙂. Now it works. Thanks a lot Leo 🙂.
