Friday, May 27, 2022

#1 2022-05-08 08:42:03 am

NMG
Member
Registered: 2019-09-29
Posts: 60

Add file://

I have an url in the clipboard and I need to add "file://" to the beginning.

I tried:
set adreca to file:// & clipboard

It gives me that error:
Expected end of line, etc. but found “:”.

How can add file:// to an address I have in the clipboard?

Offline

 

#2 2022-05-08 09:57:21 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2285

Re: Add file://

Applescript:


set thePath to (choose file) as text --> HFS path
-- or,
-- set thePath to POSIX path of (choose file) --> Posix path
set the clipboard to thePath -- this is copy to the clipboard command
-- or,
-- you don't need code lines above, because the path is already copied to the clipboard manually

tell application "System Events"
   set fileURL to URL of file (get the clipboard as text)
end tell

NOTE: the clipboard should contain the HFS path or the Posix path (and not some URL). Both of them is a text.

As for the snippet you provided, your mistakes is: 1) using "file://" without quotes, 2) using clipboard property of System Events instead of the clipboard command ("the" is required here!!!). So, proper code should be like this:

Applescript:


set adreca to "file://" & (the clipboard)

Last edited by KniazidisR (2022-05-08 11:19:01 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2022-05-09 04:14:35 am

NMG
Member
Registered: 2019-09-29
Posts: 60

Re: Add file://

thank you

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)