How to make a code to access the internet and other programs

7 ビュー (過去 30 日間)
Rainaire Hansford
Rainaire Hansford 2017 年 7 月 24 日
コメント済み: Walter Roberson 2019 年 1 月 15 日
Is there a way to make a code open the internet browser and other programs.

採用された回答

Jon Lobo
Jon Lobo 2017 年 7 月 24 日
You can use system commands to do this. See system
You can also use the ! to do this.
  6 件のコメント
Rainaire Hansford
Rainaire Hansford 2018 年 7 月 10 日
Ok Walter your going to have to walk me throught this cause I have no idea what any of this means haha I ran this code but it keeps giving error:
SWITCH expression must be a scalar or a character vector.
Error in Practice (line 11)
switch lower(parts)
Walter Roberson
Walter Roberson 2018 年 7 月 10 日
Change
switch lower(parts)
to
switch lower(parts{1})

サインインしてコメントする。

その他の回答 (1 件)

Rainaire Hansford
Rainaire Hansford 2018 年 8 月 4 日
ok well no error
What is your command parts
Undefined function or variable 'text_to_say'.
Error in Practice (line 45)
Speak(obj, text_to_say);
  15 件のコメント
Rainaire Hansford
Rainaire Hansford 2019 年 1 月 15 日
Well my chrome is in the same location. But i really dont know what im really looking at lol.
the dots before and after else i never seen them in a code before. In all the codes that we have gone over where is this suppose to fit?
Walter Roberson
Walter Roberson 2019 年 1 月 15 日
%initializations. No need to keep doing these.
chromelocation = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe';
local_file_prefix = 'file://';
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
command = strtrim( input('What is your command ', 's') );
parts = regexp(command, '\s+', 'split');
if isempty(parts)
text_to_say = 'Unrecognized command';
Speak(obj, text_to_say);
else
switch lower(parts{1})
case 'open'
if length(parts) == 2
cmd = [];
filename = parts{2};
if exist(filename, 'file')
openwhat = [local_file_prefix filename];
text_to_say = 'Opening local file';
else
uri = regexp(filename, '^\w\w+:'); %with at least two characters before the :
if isempty(uri)
text_to_say = 'Local file not found';
filename = [];
else
text_to_say = 'Opening URL with browser.';
cmd = sprintf('%s "%s" &', chromelocation, filename);
filename = [];
end
end
Speak(obj, text_to_say);
if ~isempty(filename)
open(filename);
end
if ~isempty(cmd)
cmd = sprintf('%s "%s" &', chromelocation, openwhat);
system(cmd);
end
else
Speak(obj, text_to_say);
end
case 'search'
if length(parts) == 2
filename = parts{2};
cmd = sprintf('cd C:\; dir /s "%s"', filename);
text_to_say = 'Searching disk C for file';
Speak(obj, text_to_say);
[status, message] = system(cmd);
if isempty(message)
text_to_say = 'System had no response to search request';
Speak(obj, text_to_say);
else
text_to_say = 'System result of search follows';
Speak(obj, text_to_say);
Speak(obj, message);
end
else
Speak(obj, text_to_say');
end
otherwise
Speak(obj, text_to_say);
end
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by